Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 private Task <bool> SpinWaitForRestart(SelfRestartingProcess selfRestartingProcess, int restartCount)
 {
     return(SpinWaitFor(() => selfRestartingProcess.RestartCount == restartCount));
 }