[NonParallelizable] // timing-sensitive public async Task TestFailedAcquireReleasesWhatHasAlreadyBeenAcquired() { using var @event = new ManualResetEventSlim(); var failDatabase = CreateDatabaseMock(); MockDatabase(failDatabase, () => { @event.Wait(); return(false); }); this._provider.Strategy.DatabaseProvider.Databases = new[] { RedisServer.GetDefaultServer(0).Multiplexer.GetDatabase(), failDatabase.Object }; var @lock = this._provider.CreateLock("lock"); var acquireTask = @lock.TryAcquireAsync().AsTask(); Assert.IsFalse(acquireTask.Wait(TimeSpan.FromMilliseconds(50))); @event.Set(); Assert.IsNull(await acquireTask); this._provider.Strategy.DatabaseProvider.Databases = new[] { RedisServer.GetDefaultServer(0).Multiplexer.GetDatabase() }; var singleDatabaseLock = this._provider.CreateLock("lock"); using var handle = await singleDatabaseLock.TryAcquireAsync(); Assert.IsNotNull(handle); }
public void TestAcquireWithLockPrefix() { this._provider.Strategy.DatabaseProvider.Databases = new[] { CreateDatabase(keyPrefix: "P") }; var implicitPrefixLock = this._provider.CreateLock("N"); this._provider.Strategy.DatabaseProvider.Databases = new[] { CreateDatabase() }; var noPrefixLock = this._provider.CreateLock("N"); var explicitPrefixLock = this._provider.CreateLock("PN"); using var implicitPrefixHandle = implicitPrefixLock.TryAcquire(); Assert.IsNotNull(implicitPrefixHandle); using var noPrefixHandle = noPrefixLock.TryAcquire(); Assert.IsNotNull(noPrefixHandle); using var explicitPrefixHandle = explicitPrefixLock.TryAcquire(); Assert.IsNull(explicitPrefixHandle); IDatabase CreateDatabase(string?keyPrefix = null) { var database = RedisServer.GetDefaultServer(0).Multiplexer.GetDatabase(); return(keyPrefix is null ? database : database.WithKeyPrefix(keyPrefix)); } }
static IDatabase CreateDatabase(string?keyPrefix = null) { var database = RedisServer.GetDefaultServer(0).Multiplexer.GetDatabase(); return(keyPrefix is null ? database : database.WithKeyPrefix(keyPrefix)); }
public TestingRedis2x1DatabaseProvider() : base(Enumerable.Range(0, 2).Select(i => RedisServer.GetDefaultServer(i).Multiplexer.GetDatabase()).Append(DeadDatabase)) { }
protected TestingRedisDatabaseProvider(int count) : this(Enumerable.Range(0, count).Select(i => RedisServer.GetDefaultServer(i).Multiplexer.GetDatabase())) { }
public void OneTimeTearDown() => RedisServer.DisposeAll();
public TestingRedisWithKeyPrefixSingleDatabaseProvider() : base(new[] { RedisServer.GetDefaultServer(0).Multiplexer.GetDatabase().WithKeyPrefix("distributed_locks:") }) { }