public IEnumerator CanReplay() { using (var test = StartTest()) using (var processServer = new TestProcessServer(test.TaskManager, test.Environment, test.Configuration)) { processServer.ConnectSync(); var expectedId = 0; var expectedOutput = new List <string>(); var task = processServer.NewDotNetProcess(TestApp, "-d done -b", new ProcessOptions(MonitorOptions.KeepAlive), onOutput: (t, s) => { expectedId = t.ProcessId; expectedOutput.Add(s); t.Detach(); }); task.Start(); foreach (var frame in WaitForCompletion(task)) { yield return(frame); } task.Dispose(); var actualId = 0; var actualOutput = new List <string>(); task = processServer.NewDotNetProcess(TestApp, "-d done -b", new ProcessOptions(MonitorOptions.KeepAlive), onOutput: (t, s) => { actualId = t.ProcessId; actualOutput.Add(s); t.Detach(); }); task.Start(); foreach (var frame in WaitForCompletion(task)) { yield return(frame); } task.Dispose(); Assert.Greater(expectedId, 0); Assert.AreEqual(expectedId, actualId); actualOutput.Matches(expectedOutput); } }
public IEnumerator CanExecuteAndRestartProcess() { using (var test = StartTest()) using (var processServer = new TestProcessServer(test.TaskManager, test.Environment, test.Configuration)) { processServer.ConnectSync(); var task = new ProcessTask <string>(test.TaskManager, test.ProcessManager.DefaultProcessEnvironment, TestApp, "-s 100", new StringOutputProcessor()) { Affinity = TaskAffinity.None }; task.Configure(processServer.ProcessManager, new ProcessOptions(MonitorOptions.KeepAlive, true)); var restartCount = 0; var restarted = new TaskCompletionSource <ProcessRestartReason>(); processServer.ProcessManager.OnProcessRestart += (sender, args) => { restartCount++; if (restartCount == 2) { restarted.TrySetResult(args.Reason); } }; task.Start(); var timeout = Task.Delay(4000); var wait = Task.WhenAny(restarted.Task, timeout); foreach (var frame in WaitForCompletion(wait)) { yield return(frame); } Assert.True(wait.Result != timeout, "Restart did not happen on time"); task.Detach(); Assert.AreEqual(ProcessRestartReason.KeepAlive, restarted.Task.Result); } }
//[CustomUnityTest] public IEnumerator CanReconnectToKeepAliveProcess() { using (var test = StartTest()) using (var processServer = new TestProcessServer(test.TaskManager, test.Environment, test.Configuration)) { processServer.ConnectSync(); var expected = 0; var task = processServer.NewNativeProcess(TestApp, "-b", new ProcessOptions(MonitorOptions.KeepAlive), onStart: t => { expected = t.ProcessId; t.Detach(); }); task.Start(); foreach (var frame in WaitForCompletion(task)) { yield return(frame); } task.Dispose(); var actual = 0; task = processServer.NewNativeProcess(TestApp, "-b", new ProcessOptions(MonitorOptions.KeepAlive), onStart: t => { actual = t.ProcessId; t.Detach(); }); task.Start(); foreach (var frame in WaitForCompletion(task)) { yield return(frame); } task.Dispose(); Assert.AreEqual(expected, actual); } }