Esempio n. 1
0
        public void CanEnableDisableThrottlingTimer()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(1), timerManagement: ThrottledManualResetEventSlim.TimerManagement.Manual))
            {
                mre.Set();

                Assert.False(mre.Wait((int)TimeSpan.FromSeconds(3).TotalMilliseconds, CancellationToken.None));

                mre.EnableThrottlingTimer();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(2).TotalMilliseconds, CancellationToken.None));

                mre.Reset();

                mre.DisableThrottlingTimer();

                Assert.False(mre.IsSet);

                mre.Set();

                Assert.False(mre.Wait((int)TimeSpan.FromSeconds(3).TotalMilliseconds, CancellationToken.None));

                mre.EnableThrottlingTimer();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(2).TotalMilliseconds, CancellationToken.None));
            }
        }
Esempio n. 2
0
        public void CanForceSetByIgnoringThrottling()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromHours(3)))
            {
                mre.Set();

                Assert.False(mre.IsSet);

                mre.Set(ignoreThrottling: true);

                Assert.True(mre.IsSet);
            }
        }
Esempio n. 3
0
        public void WillSetMreOnTime()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(5)))
            {
                mre.Set();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(7).TotalMilliseconds, CancellationToken.None));
            }
        }
Esempio n. 4
0
        public void ShouldNotSetMreImmediatelyWhenThrottlingEnabled()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromHours(1)))
            {
                Assert.Equal(TimeSpan.FromHours(1), mre.ThrottlingInterval);

                mre.Set();

                Assert.False(mre.IsSet);
            }
        }
Esempio n. 5
0
        public void CanUpdateThrottlingToEnableIt()
        {
            using (var mre = new ThrottledManualResetEventSlim(null))
            {
                mre.Update(TimeSpan.FromSeconds(5));

                Assert.Equal(TimeSpan.FromSeconds(5), mre.ThrottlingInterval);

                mre.Set();

                Assert.True(mre.Wait((int)TimeSpan.FromSeconds(7).TotalMilliseconds, CancellationToken.None));
            }
        }
Esempio n. 6
0
        public void ShouldSetMreImmediatelyWhenThrottlingDisabled()
        {
            using (var mre = new ThrottledManualResetEventSlim(null))
            {
                Assert.Null(mre.ThrottlingInterval);

                mre.Set();

                Assert.True(mre.IsSet);

                mre.Reset();

                Assert.False(mre.IsSet);
            }
        }
Esempio n. 7
0
        public void CanUpdateThrottlingToDisableIt()
        {
            using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(10)))
            {
                mre.Set();

                mre.Update(null);

                Assert.Null(mre.ThrottlingInterval);
                Assert.True(mre.IsSet);
            }

            using (var mre = new ThrottledManualResetEventSlim(null))
            {
                mre.Update(null);
                Assert.False(mre.IsSet);
            }
        }