public void TryEnter_WhenSemaphoreNotAvailable_ReturnsFalseImmediately() { var semaphore = new SemaphoreSlimIsolationSemaphore(GroupKey.Named("Test"), new TransientConfigurableValue<int>(1), new IgnoringStats()); semaphore.TryEnter(); var stopwatch = Stopwatch.StartNew(); Assert.False(semaphore.TryEnter()); Assert.True(stopwatch.ElapsedMilliseconds < 10); }
public void Release_WhenSemaphoreNotAvailable_MakesItAvailable() { var semaphore = new SemaphoreSlimIsolationSemaphore(GroupKey.Named("Test"), new TransientConfigurableValue<int>(1), new IgnoringStats()); semaphore.TryEnter(); Assert.False(semaphore.TryEnter()); semaphore.Release(); Assert.True(semaphore.TryEnter()); }
public void TryEnterAndReleaseALot() { var semaphore = new SemaphoreSlimIsolationSemaphore(GroupKey.Named("Test"), new TransientConfigurableValue<int>(5), new IgnoringStats()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); semaphore.Release(); Assert.True(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); semaphore.Release(); semaphore.Release(); semaphore.Release(); semaphore.Release(); semaphore.Release(); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); semaphore.Release(); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.True(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); Assert.False(semaphore.TryEnter()); semaphore.Release(); semaphore.Release(); semaphore.Release(); semaphore.Release(); semaphore.Release(); }