Commit 967acc96 authored by Nick Craver's avatar Nick Craver

Fix NoticesConnectFail

Old test mismatched heartbeats under load - this is local and server test friendly.
parent 143bc407
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
...@@ -10,28 +11,26 @@ public class ConnectFailTimeout : TestBase ...@@ -10,28 +11,26 @@ public class ConnectFailTimeout : TestBase
#if DEBUG #if DEBUG
[Fact] [Fact]
public void NoticesConnectFail() public async Task NoticesConnectFail()
{ {
SetExpectedAmbientFailureCount(-1); SetExpectedAmbientFailureCount(-1);
using (var conn = Create(allowAdmin: true)) using (var conn = Create(allowAdmin: true))
{ {
var server = conn.GetServer(conn.GetEndPoints()[0]); var server = conn.GetServer(conn.GetEndPoints()[0]);
conn.IgnoreConnect = true;
conn.ConnectionFailed += (s, a) => conn.ConnectionFailed += (s, a) =>
Output.WriteLine("Disconnected: " + EndPointCollection.ToString(a.EndPoint)); Output.WriteLine("Disconnected: " + EndPointCollection.ToString(a.EndPoint));
conn.ConnectionRestored += (s, a) => conn.ConnectionRestored += (s, a) =>
Output.WriteLine("Reconnected: " + EndPointCollection.ToString(a.EndPoint)); Output.WriteLine("Reconnected: " + EndPointCollection.ToString(a.EndPoint));
server.SimulateConnectionFailure();
Thread.Sleep(2000);
try
{
server.Ping();
Assert.True(false, "Did not expect PING to succeed");
}
catch (RedisConnectionException) { /* expected */ }
// No need to delay, we're going to try a disconnected connection immediately so it'll fail...
conn.IgnoreConnect = true;
server.SimulateConnectionFailure();
conn.IgnoreConnect = false; conn.IgnoreConnect = false;
Thread.Sleep(2000); Assert.Throws<RedisConnectionException>(() => server.Ping());
// Heartbeat should reconnect by now
await Task.Delay(5000);
var time = server.Ping(); var time = server.Ping();
Output.WriteLine(time.ToString()); Output.WriteLine(time.ToString());
} }
......
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