Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -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();
}
Expand Down
Loading