예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }