public async Task WatchdogFailureTestAsync() { var wd = new Watchdog(petTimeout: TimeSpan.FromMilliseconds(100), autoStartOnFirstPet: false); Should.Throw <WatchdogNotStartedException>(() => wd.Cancel()); Should.Throw <WatchdogNotStartedException>(() => wd.Pet(autoReset: false)); wd.Monitor(); wd.IsTriggered.ShouldBe(false); wd.IsCanceled.ShouldBe(false); wd.IsDisposed.ShouldBe(false); wd.IsMonitorStarted.ShouldBe(true); Should.Throw <WatchdogAlreadyStartedException>(() => wd.Monitor()); await 200.TryDelay(CancellationToken.None); wd.IsTriggered.ShouldBe(true); wd.IsCanceled.ShouldBe(false); wd.IsDisposed.ShouldBe(false); wd.IsMonitorStarted.ShouldBe(true); Should.Throw <WatchdogTriggeredException>(() => wd.Monitor()); Should.Throw <WatchdogTriggeredException>(() => wd.Cancel()); wd.AsTask().Result.ShouldBe(true); // Triggered wd.TryDispose(); wd.IsTriggered.ShouldBe(true); wd.IsCanceled.ShouldBe(false); wd.IsDisposed.ShouldBe(true); wd.IsMonitorStarted.ShouldBe(true); Should.Throw <WatchdogDisposedException>(() => wd.Cancel()); Should.Throw <WatchdogDisposedException>(() => wd.Pet(autoReset: false)); Should.Throw <WatchdogDisposedException>(() => wd.Monitor()); Should.Throw <WatchdogDisposedException>(() => throw wd.AsTask().Exception !); }
public void WatchdogCancelAsTaskTest() { var wd = new Watchdog(petTimeout: TimeSpan.FromMilliseconds(100), autoStartOnFirstPet: false); wd.Monitor(); wd.Cancel(); Should.Throw <WatchdogCanceledException>(() => throw wd.AsTask().Exception !); }
public void WatchdogCancelBeforeTriggeredTest() { var wd = new Watchdog(petTimeout: TimeSpan.FromMilliseconds(100), autoStartOnFirstPet: false); var wdTask = wd.AsTask(); wd.Monitor(); wd.Cancel(); wd.IsTriggered.ShouldBe(false); wd.IsCanceled.ShouldBe(true); wd.IsDisposed.ShouldBe(false); wd.IsMonitorStarted.ShouldBe(true); Should.Throw <WatchdogCanceledException>(() => throw wdTask.Exception !); Should.Throw <WatchdogCanceledException>(() => throw wd.AsTask().Exception !); }