public void TestStartKillStartAgain() { using (var watchdog = new ProcessWatchdog()) { watchdog.Start(); const string reason = "because the process shouldn't have failed"; watchdog.IsProcessRunning.Should().BeTrue(reason); watchdog.HasProcessFailed.Should().BeFalse(reason); watchdog.HostedProcessState.Should().Be(HostState.Ready, reason); watchdog.ProcessFailureReason.Should().BeNull(reason); var pid = watchdog.HostedProcessId.Value; var proc = Process.GetProcessById(pid); proc.Kill(); const string failureReason = "because we've killed the process and that failure should've been detected"; watchdog.Property(x => x.IsProcessRunning).ShouldEventually().BeFalse(failureReason); watchdog.Property(x => x.HasProcessFailed).ShouldEventually().BeTrue(failureReason); watchdog.Property(x => x.HostedProcessState).ShouldEventually().Be(HostState.Dead, failureReason); watchdog.Property(x => x.ProcessFailureReason).ShouldEventually().Be(ProcessFailureReason.HostProcessExitedUnexpectedly, failureReason); watchdog.Start(); const string newReason = "because we've restarted the process and thus everything should be back to normal again"; watchdog.IsProcessRunning.Should().BeTrue(newReason); watchdog.HasProcessFailed.Should().BeFalse(newReason); watchdog.HostedProcessState.Should().Be(HostState.Ready, newReason); watchdog.ProcessFailureReason.Should().BeNull(newReason); } }
public void SetUp() { _process = new ProcessWatchdog(); _endPoint = new SocketEndPoint(EndPointType.Client); _failureHandler = new Mock <IFailureHandler>(); _failureSettings = new FailureSettings(); _queue = new OutOfProcessQueue(_process, _endPoint, _failureHandler.Object, _failureSettings); }
public void TestDispose1() { var watchdog = new ProcessWatchdog(); watchdog.IsDisposed.Should().BeFalse(); new Action(watchdog.Dispose).ShouldNotThrow(); watchdog.IsDisposed.Should().BeTrue(); }
public void TestTryKill() { using (var watchdog = new ProcessWatchdog()) { watchdog.Start(); watchdog.RemotePort.Should().HaveValue(); watchdog.IsProcessRunning.Should().BeTrue(); watchdog.HasProcessFailed.Should().BeFalse(); watchdog.TryKill(); watchdog.RemotePort.Should().NotHaveValue(); watchdog.IsProcessRunning.Should().BeFalse(); watchdog.HasProcessFailed.Should().BeTrue(); } }
public void TestDispose2() { ProcessWatchdog watchdog; using (watchdog = new ProcessWatchdog()) { watchdog.RemotePort.Should().NotHaveValue(); watchdog.HostedProcessId.Should().NotHaveValue(); watchdog.Start(); watchdog.RemotePort.Should().HaveValue(); watchdog.HostedProcessId.Should().HaveValue(); } watchdog.RemotePort.Should().NotHaveValue(); watchdog.HostedProcessId.Should().NotHaveValue(); }
public void TestStartKillStart() { using (var watchdog = new ProcessWatchdog()) { watchdog.Start(); watchdog.IsProcessRunning.Should().BeTrue(); watchdog.HasProcessFailed.Should().BeFalse(); var pid = watchdog.HostedProcessId.Value; var proc = Process.GetProcessById(pid); proc.Kill(); watchdog.Start(); watchdog.IsProcessRunning.Should().BeTrue("Because we've just started that process again"); watchdog.HasProcessFailed.Should().BeFalse("Because we've just started that process again"); } }
public void TestStartKill() { using (var watchdog = new ProcessWatchdog()) { watchdog.Start(); watchdog.IsProcessRunning.Should().BeTrue(); watchdog.HasProcessFailed.Should().BeFalse(); var pid = watchdog.HostedProcessId.Value; var proc = Process.GetProcessById(pid); proc.Kill(); watchdog.Property(x => x.HasProcessFailed).ShouldEventually().BeTrue(); watchdog.Property(x => x.IsProcessRunning).ShouldEventually().BeFalse(); watchdog.Property(x => x.ProcessFailureReason).ShouldEventually().Be(ProcessFailureReason.HostProcessExitedUnexpectedly); } }
public void TestTryKill() { using (var watchdog = new ProcessWatchdog()) { watchdog.Start(); watchdog.RemotePort.Should().HaveValue(); watchdog.IsProcessRunning.Should().BeTrue(); watchdog.HasProcessFailed.Should().BeFalse(); watchdog.ProcessFailureReason.Should().BeNull("because the process shouldn't have failed"); watchdog.TryKill(); watchdog.RemotePort.Should().NotHaveValue(); watchdog.IsProcessRunning.Should().BeFalse(); watchdog.HasProcessFailed.Should().BeTrue(); watchdog.ProcessFailureReason.Should() .BeNull("because we've explicitly killed the process and thus no fault occured"); } }
public OutOfProcessQueue( ProcessWatchdog process, ISocketEndPoint endPoint, IFailureHandler failureHandler, FailureSettings failureSettings ) { if (process == null) { throw new ArgumentNullException(nameof(process)); } if (endPoint == null) { throw new ArgumentNullException(nameof(endPoint)); } if (failureHandler == null) { throw new ArgumentNullException(nameof(failureHandler)); } if (failureSettings == null) { throw new ArgumentNullException(nameof(failureSettings)); } _syncRoot = new object(); _process = process; _process.OnFaultDetected += ProcessOnOnFaultDetected; _endPoint = endPoint; _endPoint.OnFailure += EndPointOnOnFailure; _failureHandler = failureHandler; _failureSettings = failureSettings; _actions = new ConcurrentQueue <Operation>(); _thread = new Thread(Do); _thread.Start(); }
public void TestDispose2() { ProcessWatchdog watchdog; int pid; using (watchdog = new ProcessWatchdog()) { watchdog.RemotePort.Should().NotHaveValue(); watchdog.HostedProcessId.Should().NotHaveValue(); watchdog.Start(); watchdog.RemotePort.Should().HaveValue(); watchdog.HostedProcessId.Should().HaveValue(); pid = watchdog.HostedProcessId.Value; ProcessWithPidShouldBeRunning(pid); } watchdog.RemotePort.Should().NotHaveValue(); watchdog.HostedProcessId.Should().NotHaveValue(); ProcessWithPidShouldNotBeRunning(pid); }
public void TestDispose1() { var watchdog = new ProcessWatchdog(); new Action(watchdog.Dispose).ShouldNotThrow(); }