diff --git a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs index e237509d..b088e9dc 100644 --- a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs +++ b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/IntegrationFixture.cs @@ -15,6 +15,7 @@ public sealed class IntegrationFixture : IAsyncInitializer, IAsyncDisposable { readonly ActivityListener _listener = DummyActivityListener.Create(); RedisContainer _redisContainer = null!; + ConnectionMultiplexer _muxer = null!; IEventSerializer Serializer { get; } = new DefaultEventSerializer(TestPrimitives.DefaultOptions); @@ -25,6 +26,14 @@ public async Task InitializeAsync() { await _redisContainer.StartAsync(); var connString = _redisContainer.GetConnectionString(); + + // FLUSHDB in test teardown is an admin command; StackExchange.Redis 3.x enforces the + // admin gate for raw commands issued through Execute as well. + // abortConnect=false keeps the multiplexer retrying when the first connection attempt + // races the freshly started container. The multiplexer is shared by all tests, as one + // connection per process is how StackExchange.Redis is meant to be used. + _muxer = await ConnectionMultiplexer.ConnectAsync($"{connString},allowAdmin=true,abortConnect=false"); + await Module.LoadModule(GetDb); GetDatabase = GetDb; @@ -34,16 +43,11 @@ public async Task InitializeAsync() { return; - IDatabase GetDb() { - // FLUSHDB in test teardown is an admin command; StackExchange.Redis 3.x enforces the - // admin gate for raw commands issued through Execute as well. - var muxer = ConnectionMultiplexer.Connect($"{connString},allowAdmin=true"); - - return muxer.GetDatabase(); - } + IDatabase GetDb() => _muxer.GetDatabase(); } public async ValueTask DisposeAsync() { + _muxer.Dispose(); await _redisContainer.DisposeAsync(); _listener.Dispose(); }