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);
        }
Example #3
0
        public async Task TestThatExitedEventIsEmittedWhenProcessFails()
        {
            ProcessStub process = new ProcessStub("", "");
            IProcessFactory processFactory = new StubIProcessFactory()
            {
                CreateProcessStringString = (path, args) => process
            };

            ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, new StubIProcessStopper());
            ApplicationExitedArgs appExitedArgs = null;
            int exitedEventCount = 0;
            application.Exited += (sender, args) =>
            {
                appExitedArgs = args;
                ++exitedEventCount;
            };
            await application.Start();
            process.RaiseExitedEvent();

            Assert.AreEqual(1, exitedEventCount);
            Assert.AreEqual(_appIdentity, appExitedArgs.AppIdentity);
        }