public void TestLockTimesOut() { RedisDistributedLockProvider provider = new RedisDistributedLockProvider(new RedisDistributedLockProviderOptions (this, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(2))); acquired = false; try { IDisposable theLock = provider.AcquireLock("Test", new Context(), default); } catch (OperationCanceledException) { return; } throw new Exception($"{nameof(OperationCanceledException)} should have been thrown"); }
public void TestExceptionNotifierExecutes() { Exception foundEx = null; void exceptionNotifier(Exception ex) { foundEx = ex; } RedisDistributedLockProvider provider = new RedisDistributedLockProvider(new RedisDistributedLockProviderOptions (this, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(10), exceptionNotifier)); acquired = true; throwException = new Exception("Test"); IDisposable theLock = provider.AcquireLock("Test", new Context(), default); theLock.Dispose(); foundEx.Should().NotBeNull(); released.Should().BeTrue(); }