public void CanThrottleWithDropBehavior() { const int executionLimit = 100; int executionCounter = 0; var throttler = new TimeLimitCommandThrottler(executionLimit); Parallel.For(0, executionLimit*10, i => throttler.Execute(() => Interlocked.Increment(ref executionCounter))); executionCounter.ShouldEqual(executionLimit); }
public void CanThrottleWithBlockBehavior() { const int executionLimit = 10; int executionCounter = 0; var throttler = new TimeLimitCommandThrottler(executionLimit, 50, TimeLimitCommandThrottler.CommandThrottlerLimitingBehavior.Block); var sw = Stopwatch.StartNew(); Parallel.For(0, executionLimit * 2, i => throttler.Execute(() => Interlocked.Increment(ref executionCounter))); sw.ElapsedMilliseconds.ShouldBeGreaterThan(50); executionCounter.ShouldEqual(2* executionLimit); }