Commit bb2c0a77 authored by Nick Craver's avatar Nick Craver

Tests: fix ConnectWithWrongPassword

This failed under unit test load due to unintended retries during periods where async continuations for completion of the test don't occur before retries kick in and change an auth exception to a socket exception (which we correctly already closed).

Still, I think we should consider storing the initial connection error seperately from others as there's a fundamental race of an error that an observer cannot see when retries overwrite the last error message.
parent 023232cf
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
......@@ -72,20 +73,22 @@ public void Connect()
[Theory]
[InlineData("wrong")]
[InlineData("")]
public void ConnectWithWrongPassword(string password)
public async Task ConnectWithWrongPassword(string password)
{
var ex = Assert.Throws<AggregateException>(() =>
var config = ConfigurationOptions.Parse(GetConfiguration());
config.Password = password;
config.ConnectRetry = 0; // we don't want to retry on closed sockets in this case.
var ex = await Assert.ThrowsAsync<RedisConnectionException>(async () =>
{
SetExpectedAmbientFailureCount(-1);
using (var server = Create(password: password, checkConnect: false))
using (var conn = await ConnectionMultiplexer.ConnectAsync(config, Writer).ConfigureAwait(false))
{
server.GetDatabase().Ping();
conn.GetDatabase().Ping();
}
});
Assert.Single(ex.InnerExceptions);
var rce = Assert.IsType<RedisConnectionException>(ex.InnerException);
Output.WriteLine("Exception: " + rce.Message);
Assert.Equal("It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. AuthenticationFailure on PING", rce.Message);
}).ConfigureAwait(false);
Output.WriteLine("Exception: " + ex.Message);
Assert.Equal("It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. AuthenticationFailure on PING", ex.Message);
}
}
}
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