-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add redis db fixture * test: add test for redis database fixture * chore: ci changes * chore: adjust FixedSizeObjectPool test timeouts * chore: disable parallelization for FixedSizeObjectPool tests
- Loading branch information
1 parent
9c6327a
commit 998bb21
Showing
5 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using StackExchange.Redis; | ||
using Xunit; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
public class RedisDatabaseFixture<TMultiplexerFixture>(TMultiplexerFixture multiplexerFixture) | ||
: RedisDatabaseFixture(multiplexerFixture.Multiplexer) | ||
where TMultiplexerFixture : IRedisMultiplexerFixture; | ||
|
||
public class RedisDatabaseFixture : IAsyncLifetime | ||
{ | ||
private bool _disposed; | ||
|
||
private readonly IConnectionMultiplexer _multiplexer; | ||
|
||
private readonly Lazy<Task<IEphemeralRedisDatabase>> _database; | ||
|
||
public IEphemeralRedisDatabase Database => _database.Value.Result; | ||
|
||
public RedisDatabaseFixture() | ||
{ | ||
_database = new(CreateDatabaseAsync); | ||
} | ||
|
||
protected RedisDatabaseFixture(IConnectionMultiplexer multiplexer) : this() | ||
{ | ||
_multiplexer = multiplexer; | ||
} | ||
|
||
protected virtual Task<IEphemeralRedisDatabase> CreateDatabaseAsync() => | ||
Task.FromResult(_multiplexer.GetEphemeralDatabase()); | ||
|
||
public async Task InitializeAsync() => await _database.Value; | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
if (_disposed || !_database.IsValueCreated) return; | ||
|
||
_disposed = true; | ||
|
||
await Database.DisposeAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/Ephemerally.Redis.Tests/Fixtures/RedisDatabaseFixtureTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Ephemerally.Redis.Xunit; | ||
using Shouldly; | ||
|
||
namespace Ephemerally.Redis.Tests.Fixtures; | ||
|
||
[Collection(RedisDatabaseFixtureTestCollection.Name)] | ||
public class RedisDatabaseFixtureTests(RedisDatabaseFixture<RedisDatabaseFixtureTestCollectionFixture> databaseFixture) | ||
: IClassFixture<RedisDatabaseFixture<RedisDatabaseFixtureTestCollectionFixture>> | ||
{ | ||
[Fact] | ||
public void Database_should_not_be_null() | ||
{ | ||
databaseFixture.Database.ShouldNotBeNull(); | ||
} | ||
} | ||
|
||
[CollectionDefinition(Name)] | ||
public class RedisDatabaseFixtureTestCollection | ||
: ICollectionFixture<RedisDatabaseFixtureTestCollectionFixture> | ||
{ | ||
public const string Name = nameof(RedisDatabaseFixtureTestCollection); | ||
} | ||
|
||
public class RedisDatabaseFixtureTestCollectionFixture | ||
: PooledEphemeralRedisMultiplexerFixture<RedisInstanceFixture7>; |