Commit 2777240f authored by Marc Gravell's avatar Marc Gravell

record failure logs even if none passed in

parent 6a340235
...@@ -203,68 +203,81 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer) ...@@ -203,68 +203,81 @@ protected IServer GetAnyMaster(ConnectionMultiplexer muxer)
string configuration = null, string configuration = null,
[CallerMemberName] string caller = null) [CallerMemberName] string caller = null)
{ {
configuration = configuration ?? GetConfiguration(); StringWriter localLog = null;
var config = ConfigurationOptions.Parse(configuration); if(log == null)
if (disabledCommands != null && disabledCommands.Length != 0)
{ {
config.CommandMap = CommandMap.Create(new HashSet<string>(disabledCommands), false); log = localLog = new StringWriter();
} }
else if (enabledCommands != null && enabledCommands.Length != 0) try
{ {
config.CommandMap = CommandMap.Create(new HashSet<string>(enabledCommands), true); configuration = configuration ?? GetConfiguration();
} var config = ConfigurationOptions.Parse(configuration);
if (disabledCommands != null && disabledCommands.Length != 0)
{
config.CommandMap = CommandMap.Create(new HashSet<string>(disabledCommands), false);
}
else if (enabledCommands != null && enabledCommands.Length != 0)
{
config.CommandMap = CommandMap.Create(new HashSet<string>(enabledCommands), true);
}
if (Debugger.IsAttached) if (Debugger.IsAttached)
{ {
syncTimeout = int.MaxValue; syncTimeout = int.MaxValue;
} }
if (channelPrefix != null) config.ChannelPrefix = channelPrefix; if (channelPrefix != null) config.ChannelPrefix = channelPrefix;
if (tieBreaker != null) config.TieBreaker = tieBreaker; if (tieBreaker != null) config.TieBreaker = tieBreaker;
if (password != null) config.Password = string.IsNullOrEmpty(password) ? null : password; if (password != null) config.Password = string.IsNullOrEmpty(password) ? null : password;
if (clientName != null) config.ClientName = clientName; if (clientName != null) config.ClientName = clientName;
else if (caller != null) config.ClientName = caller; else if (caller != null) config.ClientName = caller;
if (syncTimeout != null) config.SyncTimeout = syncTimeout.Value; if (syncTimeout != null) config.SyncTimeout = syncTimeout.Value;
if (allowAdmin != null) config.AllowAdmin = allowAdmin.Value; if (allowAdmin != null) config.AllowAdmin = allowAdmin.Value;
if (keepAlive != null) config.KeepAlive = keepAlive.Value; if (keepAlive != null) config.KeepAlive = keepAlive.Value;
if (connectTimeout != null) config.ConnectTimeout = connectTimeout.Value; if (connectTimeout != null) config.ConnectTimeout = connectTimeout.Value;
if (proxy != null) config.Proxy = proxy.Value; if (proxy != null) config.Proxy = proxy.Value;
var watch = Stopwatch.StartNew(); var watch = Stopwatch.StartNew();
var task = ConnectionMultiplexer.ConnectAsync(config, log); var task = ConnectionMultiplexer.ConnectAsync(config, log);
if (!task.Wait(config.ConnectTimeout >= (int.MaxValue / 2) ? int.MaxValue : config.ConnectTimeout * 2)) if (!task.Wait(config.ConnectTimeout >= (int.MaxValue / 2) ? int.MaxValue : config.ConnectTimeout * 2))
{
task.ContinueWith(x =>
{ {
try task.ContinueWith(x =>
{ {
GC.KeepAlive(x.Exception); try
} {
catch GC.KeepAlive(x.Exception);
{ } }
}, TaskContinuationOptions.OnlyOnFaulted); catch
throw new TimeoutException("Connect timeout"); { }
} }, TaskContinuationOptions.OnlyOnFaulted);
watch.Stop(); throw new TimeoutException("Connect timeout");
if (Output == null) }
{ watch.Stop();
Assert.True(false, "Failure: Be sure to call the TestBase constuctor like this: BasicOpsTests(ITestOutputHelper output) : base(output) { }"); if (Output == null)
{
Assert.True(false, "Failure: Be sure to call the TestBase constuctor like this: BasicOpsTests(ITestOutputHelper output) : base(output) { }");
}
Log("Connect took: " + watch.ElapsedMilliseconds + "ms");
var muxer = task.Result;
if (checkConnect && (muxer == null || !muxer.IsConnected))
{
// If fail is true, we throw.
Assert.False(fail, failMessage + "Server is not available");
Skip.Inconclusive(failMessage + "Server is not available");
}
muxer.InternalError += OnInternalError;
muxer.ConnectionFailed += OnConnectionFailed;
muxer.MessageFaulted += (msg, ex, origin) => Writer?.WriteLine($"Faulted from '{origin}': '{msg}' - '{(ex == null ? "(null)" : ex.Message)}'");
muxer.Connecting += (e, t) => Writer.WriteLine($"Connecting to {Format.ToString(e)} as {t}");
muxer.TransactionLog += msg => { lock (Writer) { Writer.WriteLine("tran: " + msg); } };
muxer.Resurrecting += (e, t) => Writer.WriteLine($"Resurrecting {Format.ToString(e)} as {t}");
muxer.Closing += complete => Writer.WriteLine(complete ? "Closed" : "Closing...");
return muxer;
} }
Log("Connect took: " + watch.ElapsedMilliseconds + "ms"); catch
var muxer = task.Result;
if (checkConnect && (muxer == null || !muxer.IsConnected))
{ {
// If fail is true, we throw. if (localLog != null) Output?.WriteLine(localLog.ToString());
Assert.False(fail, failMessage + "Server is not available"); throw;
Skip.Inconclusive(failMessage + "Server is not available");
} }
muxer.InternalError += OnInternalError;
muxer.ConnectionFailed += OnConnectionFailed;
muxer.MessageFaulted += (msg, ex, origin) => Writer?.WriteLine($"Faulted from '{origin}': '{msg}' - '{(ex == null ? "(null)" : ex.Message)}'");
muxer.Connecting += (e, t) => Writer.WriteLine($"Connecting to {Format.ToString(e)} as {t}");
muxer.TransactionLog += msg => { lock (Writer) { Writer.WriteLine("tran: " + msg); } };
muxer.Resurrecting += (e, t) => Writer.WriteLine($"Resurrecting {Format.ToString(e)} as {t}");
muxer.Closing += complete => Writer.WriteLine(complete ? "Closed" : "Closing...");
return muxer;
} }
public static string Me([CallerFilePath] string filePath = null, [CallerMemberName] string caller = null) => public static string Me([CallerFilePath] string filePath = null, [CallerMemberName] string caller = null) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment