public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => Task.FromResult(true), Kill = () => { hasExited = true; return(Task.FromResult(true)); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return(Task.FromResult(true)); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public async Task TestThatStopStopsTheProcess() { int stopCallCount = 0; IProcess process = new StubIProcess() { Start = () => Task.FromResult(true) }; IProcessStopper processStopper = new StubIProcessStopper { StopProcess_IProcess = (p) => { ++stopCallCount; return(Task.FromResult(true)); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcess_String_String = (path, args) => process }; ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); await application.Stop(); Assert.Equal(1, stopCallCount); }
public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => { hasExited = true; return(Task.FromResult(true)); }) .Kill(() => { throw new Exception("Kill should not be called if the process has exited gracefully"); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return(Task.FromResult(true)); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }
public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => { hasExited = true; return(Task.FromResult(true)); }, Kill = () => { throw new Exception("Kill should not be called if the process has exited gracefully"); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return(Task.FromResult(true)); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { hasExited = true; return(Task.FromResult(true)); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return(Task.FromResult(true)); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }
public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => { hasExited = true; return Task.FromResult(true); }) .Kill(() => { throw new Exception("Kill should not be called if the process has exited gracefully"); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return Task.FromResult(true); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }
public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => { hasExited = true; return Task.FromResult(true); }, Kill = () => { throw new Exception("Kill should not be called if the process has exited gracefully"); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return Task.FromResult(true); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public void TestThatProcessIsStoppedGracefullyFirst() { bool resourcesReleased = false; IProcess process = new StubIProcess { Close = () => { throw new Exception("Close should not be called if the process has exited gracefully"); }, Kill = () => { throw new Exception("Kill should not be called if the process has exited gracefully"); }, HasExited_Get = () => true, IProcessInfo_ExePath_Get = () => "exePath", IProcessInfo_ExeArgs_Get = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return(Task.FromResult(true)); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(resourcesReleased); }
public async Task TestThatStartFailsIfProcessFailsToStart() { IProcess process = new StubIProcess() .Start(args => { throw new Exception("Process failed to start"); }); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => process); IProcessStopper processStopper = new StubIProcessStopper(); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); Assert.False(await application.Start()); }
public void TestThatExceptionIsCaughtAndSwallowedIfKillBlowsUp() { IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { throw new Exception("Process would not die!"); }) .HasExited_Get(() => false) .ExePath_Get(() => "exePath"); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); }
public void TestThatExceptionIsCaughtAndSwallowedIfKillBlowsUp() { IProcess process = new StubIProcess { Close = () => Task.FromResult(true), Kill = () => { throw new Exception("Process would not die!"); }, HasExitedGet = () => false, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); }
public async Task TestStartProcessHappyPath() { int startCallCount = 0; int stopCallCount = 0; IProcess process = new StubIProcess() { Start = () => { startCallCount++; return(Task.FromResult(true)); } }; string exePath = ""; string exeArgs = ""; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcess_String_String = (path, args) => { exePath = path; exeArgs = args; return(process); } }; IProcessStopper processStopper = new StubIProcessStopper { StopProcess_IProcess = (p) => { ++stopCallCount; return(Task.FromResult(true)); } }; ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); Assert.Equal(1, startCallCount); Assert.Equal(0, stopCallCount); Assert.Equal(ApplicationTestFixture.TestExeArgs, exeArgs); Assert.Equal(Path.Combine(ApplicationTestFixture.AppPath, ApplicationTestFixture.ExeName), exePath); }
public async Task TestStartProcessHappyPath() { int startCallCount = 0; int stopCallCount = 0; IProcess process = new StubIProcess() { Start = () => { startCallCount++; return Task.FromResult(true); } }; string exePath = ""; string exeArgs = ""; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcessStringString = (path, args) => { exePath = path; exeArgs = args; return process; } }; IProcessStopper processStopper = new StubIProcessStopper { StopProcessIProcess = (p) => { ++stopCallCount; return Task.FromResult(true); } }; ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper); await application.Start(); Assert.AreEqual(1, startCallCount); Assert.AreEqual(0, stopCallCount); Assert.AreEqual(TestExeArgs, exeArgs); Assert.AreEqual(Path.Combine(AppPath, ExeName), exePath); }
public async Task TestThatStartFailsIfProcessFailsToStart() { IProcess process = new StubIProcess() { Start = () => { throw new Exception("Process failed to start"); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcessStringString = (path, args) => process }; IProcessStopper processStopper = new StubIProcessStopper(); ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper); Assert.IsFalse(await application.Start()); }
public async Task TestStartProcessHappyPath() { int startCallCount = 0; int stopCallCount = 0; string exePath = ""; string exeArgs = ""; IProcess process = new StubIProcess() .Start(args => { exeArgs = args; startCallCount++; return(Task.FromResult(true)); } ); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => { exePath = path; return(process); }); IProcessStopper processStopper = new StubIProcessStopper() .StopProcess(p => { ++stopCallCount; return(Task.FromResult(true)); } ); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); Assert.Equal(1, startCallCount); Assert.Equal(0, stopCallCount); Assert.Equal(ApplicationTestFixture.TestExeArgs, exeArgs); Assert.Equal(Path.Combine(ApplicationTestFixture.AppPath, ApplicationTestFixture.ExeName), exePath); }
public async Task TestThatStartFailsIfProcessFailsToStart() { IProcess process = new StubIProcess() { Start = () => { throw new Exception("Process failed to start"); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcess_String_String = (path, args) => process }; IProcessStopper processStopper = new StubIProcessStopper(); ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); Assert.False(await application.Start()); }
public async Task TestThatExitedEventIsNotFiredOnGracefulShutdown() { var yamsConfig = new YamsConfigBuilder("clusterId", "1", "instanceId", "C:\\Foo").Build(); var process = new StubIProcess().HasExited_Get(() => true); IIpcConnection connection = new StubIIpcConnection() .SendMessage(message => { process.Exited_Raise(process, new ProcessExitedArgs(process, "")); return(Task.CompletedTask); }) .Disconnect(() => Task.CompletedTask); GracefulShutdownProcessDecorator decorator = new GracefulShutdownProcessDecorator(yamsConfig, process, connection); bool hasExitedFired = false; decorator.Exited += (sender, args) => { hasExitedFired = true; }; await decorator.Close(); Assert.False(hasExitedFired); }
public async Task TestThatStopStopsTheProcess() { int stopCallCount = 0; IProcess process = new StubIProcess().Start(args => Task.FromResult(true)); IProcessStopper processStopper = new StubIProcessStopper() .StopProcess(p => { ++stopCallCount; return(Task.FromResult(true)); } ); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => process); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); await application.Stop(); Assert.Equal(1, stopCallCount); }
public async Task TestThatStopStopsTheProcess() { int stopCallCount = 0; IProcess process = new StubIProcess() { Start = () => Task.FromResult(true) }; IProcessStopper processStopper = new StubIProcessStopper { StopProcessIProcess = (p) => { ++stopCallCount; return Task.FromResult(true); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcessStringString = (path, args) => process }; ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper); await application.Start(); await application.Stop(); Assert.AreEqual(1, stopCallCount); }
public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => Task.FromResult(true), Kill = () => { hasExited = true; return Task.FromResult(true); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return Task.FromResult(true); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public void TestThatExceptionIsCaughtAndSwallowedIfKillBlowsUp() { IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { throw new Exception("Process would not die!"); }) .HasExited_Get(() => false) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs"); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); }
public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { hasExited = true; return Task.FromResult(true); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return Task.FromResult(true); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }