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)); } }
public void WillSetMreOnTime() { using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromSeconds(5))) { mre.Set(); Assert.True(mre.Wait((int)TimeSpan.FromSeconds(7).TotalMilliseconds, CancellationToken.None)); } }
public void ShouldNotSetMreImmediatelyWhenThrottlingEnabled() { using (var mre = new ThrottledManualResetEventSlim(TimeSpan.FromHours(1))) { Assert.Equal(TimeSpan.FromHours(1), mre.ThrottlingInterval); mre.Set(); Assert.False(mre.IsSet); } }
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)); } }
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); } }
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); } }
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); } }