public void sequence_is_incremented() { var throttler = new SequenceThrottle(10); throttler.RequestResource(1); throttler.RequestResource(2); Assert.AreEqual(2, (int)throttler.CurrentSequence); }
public void releasing_resources_prevents_blocking() { var throttler = new SequenceThrottle(2); throttler.RequestResource(1); throttler.RequestResource(2); throttler.RemoveOne(2); throttler.RequestResource(3); // This would block indefinitely if releasing did not work }
public void exhausting_threshold_causes_blocking() { var throttler = new SequenceThrottle(2); ThreadPool.QueueUserWorkItem(s => { Thread.Sleep(3000); throttler.RemoveMany(2); }); throttler.RequestResource(1); throttler.RequestResource(2); throttler.RequestResource(3); // This resource will block until a sequence is released laterally }