public async Task TestThatProcessIsRestarted() { ProcessStub process = new ProcessStub("exePath", "exeArgs"); SelfRestartingProcess selfRestartingProcess = new SelfRestartingProcess(process, 1); await selfRestartingProcess.Start(); Assert.IsTrue(process.IsRunning); process.RaiseExitedEvent(); Assert.IsTrue(await SpinWaitForRestart(selfRestartingProcess, 1)); Assert.IsTrue(process.IsRunning); }
public async Task TestThatExitedIsRaisedIfProcessFailsToRestart() { ProcessStub process = new ProcessStub("exePath", "exeArgs"); SelfRestartingProcess selfRestartingProcess = new SelfRestartingProcess(process, 1); bool exitedFired = false; selfRestartingProcess.Exited += (sender, args) => { exitedFired = true; }; await selfRestartingProcess.Start(); Assert.IsTrue(process.IsRunning); process.ShouldStart = false; process.RaiseExitedEvent(); Assert.IsTrue(await SpinWaitFor(() => exitedFired)); Assert.IsFalse(process.IsRunning); Assert.IsTrue(exitedFired); }
public async Task TestThatExitedIsRaisedIfProcessMaxRetryCountIsReached() { ProcessStub process = new ProcessStub("exePath"); SelfRestartingProcess selfRestartingProcess = new SelfRestartingProcess(process, 1); bool exitedFired = false; selfRestartingProcess.Exited += (sender, args) => { exitedFired = true; }; await selfRestartingProcess.Start("exeArgs"); Assert.True(process.IsRunning); process.RaiseExitedEvent(); Assert.True(await SpinWaitForRestart(selfRestartingProcess, 1)); Assert.True(process.IsRunning); process.RaiseExitedEvent(); Assert.True(await SpinWaitFor(() => exitedFired)); Assert.False(process.IsRunning); Assert.True(exitedFired); }
private Task <bool> SpinWaitForRestart(SelfRestartingProcess selfRestartingProcess, int restartCount) { return(SpinWaitFor(() => selfRestartingProcess.RestartCount == restartCount)); }