Beispiel #1
0
        public void ItPausesWhenNeeded_DebuggingTest()
        {
            log.WriteLine("Starting test at " + DateTimeOffset.UtcNow.ToString("HH:mm:ss.fff"));

            // Arrange - The number of calls exceeds the max frequency by one
            const int FREQUENCY = 60;
            const int CALLS     = FREQUENCY + 1;
            var       target    = new PerMinuteCounter(FREQUENCY, "test", this.targetLogger);

            // Act
            var pauses = 0;

            for (int i = 0; i < CALLS; i++)
            {
                pauses += target.IncreaseAsync(CancellationToken.None).Result ? 1 : 0;
            }

            // Assert - The counter throttled the call once
            Assert.Equal(1, pauses);
        }
Beispiel #2
0
        public void ItDoesntPauseWhenNotNeeded()
        {
            log.WriteLine("Starting test at " + DateTimeOffset.UtcNow.ToString("HH:mm:ss.fff"));

            // Arrange - The number of calls doesn't exceed the max frequency
            const int FREQUENCY = 60;
            const int CALLS     = FREQUENCY;
            var       target    = new PerMinuteCounter(FREQUENCY, "test", this.targetLogger);

            // Act
            var paused = false;

            for (int i = 0; i < CALLS; i++)
            {
                paused = paused || target.IncreaseAsync(CancellationToken.None).Result;
            }

            // Assert - The counter never throttled the call
            Assert.False(paused);
        }