public async Task RunIPCEndToEnd() { using (var server = new ProcessChannel()) { JobRequestMessage result = null; TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = null; JobEnvironment environment = new JobEnvironment(); List<TaskInstance> tasks = new List<TaskInstance>(); Guid JobId = Guid.NewGuid(); var jobRequest = new JobRequestMessage(plan, timeline, JobId, "someJob", environment, tasks); Process jobProcess; server.StartServer((p1, p2) => { string clientFileName = $"Test{IOUtil.ExeExtension}"; jobProcess = new Process(); jobProcess.StartInfo.FileName = clientFileName; jobProcess.StartInfo.Arguments = "spawnclient " + p1 + " " + p2; jobProcess.EnableRaisingEvents = true; jobProcess.Start(); }); var cs = new CancellationTokenSource(); await server.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(jobRequest), cs.Token); var packetReceiveTask = server.ReceiveAsync(cs.Token); Task[] taskToWait = { packetReceiveTask, Task.Delay(30*1000) }; await Task.WhenAny(taskToWait); bool timedOut = !packetReceiveTask.IsCompleted; // Wait until response is received if (timedOut) { cs.Cancel(); try { await packetReceiveTask; } catch (OperationCanceledException) { // Ignore OperationCanceledException and TaskCanceledException exceptions } catch (AggregateException errors) { // Ignore OperationCanceledException and TaskCanceledException exceptions errors.Handle(e => e is OperationCanceledException); } } else { result = JsonUtility.FromString<JobRequestMessage>(packetReceiveTask.Result.Body); } // Wait until response is received if (timedOut) { Assert.True(false, "Test timed out."); } else { Assert.True(jobRequest.JobId.Equals(result.JobId) && jobRequest.JobName.Equals(result.JobName)); } } }
public async Task RunIPCEndToEnd() { using (var server = new ProcessChannel()) { JobRequestMessage result = null; TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = null; JobEnvironment environment = new JobEnvironment(); List <TaskInstance> tasks = new List <TaskInstance>(); Guid JobId = Guid.NewGuid(); var jobRequest = new JobRequestMessage(plan, timeline, JobId, "someJob", environment, tasks); Process jobProcess; server.StartServer((p1, p2) => { string clientFileName = $"Test{IOUtil.ExeExtension}"; jobProcess = new Process(); jobProcess.StartInfo.FileName = clientFileName; jobProcess.StartInfo.Arguments = "spawnclient " + p1 + " " + p2; jobProcess.EnableRaisingEvents = true; jobProcess.Start(); }); var cs = new CancellationTokenSource(); await server.SendAsync(MessageType.NewJobRequest, JsonUtility.ToString(jobRequest), cs.Token); var packetReceiveTask = server.ReceiveAsync(cs.Token); Task[] taskToWait = { packetReceiveTask, Task.Delay(5000) }; await Task.WhenAny(taskToWait); bool timedOut = !packetReceiveTask.IsCompleted; // Wait until response is received if (timedOut) { cs.Cancel(); try { await packetReceiveTask; } catch (OperationCanceledException) { // Ignore OperationCanceledException and TaskCanceledException exceptions } catch (AggregateException errors) { // Ignore OperationCanceledException and TaskCanceledException exceptions errors.Handle(e => e is OperationCanceledException); } } else { result = JsonUtility.FromString <JobRequestMessage>(packetReceiveTask.Result.Body); } // Wait until response is received if (timedOut) { Assert.True(false, "Test timed out."); } else { Assert.True(jobRequest.JobId.Equals(result.JobId) && jobRequest.JobName.Equals(result.JobName)); } } }