public async Task ServerRunning_ShutdownRequest_DoesNotAbortCompilation() { // Arrange var completionSource = new TaskCompletionSource <bool>(); var host = CreateCompilerHost(c => c.ExecuteFunc = (req, ct) => { // We want this to keep running even after the shutdown is seen. completionSource.Task.Wait(); return(EmptyServerResponse); }); using (var serverData = ServerUtilities.CreateServer(compilerHost: host)) { var compileTask = ServerUtilities.Send(serverData.PipeName, EmptyServerRequest); // Act // The compilation is now in progress, send the shutdown. await ServerUtilities.SendShutdown(serverData.PipeName); Assert.False(compileTask.IsCompleted); // Now let the task complete. completionSource.SetResult(true); // Assert var response = await compileTask; Assert.Equal(ServerResponse.ResponseType.Completed, response.Type); Assert.Equal(0, ((CompletedServerResponse)response).ReturnCode); await serverData.Verify(connections : 2, completed : 2); } }
public async Task ServerRunning_ShutdownRequest_processesSuccessfully() { // Arrange using (var serverData = ServerUtilities.CreateServer()) { // Act var serverProcessId = await ServerUtilities.SendShutdown(serverData.PipeName); // Assert Assert.Equal(Process.GetCurrentProcess().Id, serverProcessId); await serverData.Verify(connections : 1, completed : 1); } }
public async Task ServerRunning_MultipleShutdownRequests_HandlesSuccessfully() { // Arrange var startCompilationSource = new TaskCompletionSource <bool>(); var finishCompilationSource = new TaskCompletionSource <bool>(); var host = CreateCompilerHost(c => c.ExecuteFunc = (req, ct) => { // At this point, the connection has been accepted and the compilation has started. startCompilationSource.SetResult(true); // We want this to keep running even after the shutdown is seen. finishCompilationSource.Task.Wait(); return(EmptyServerResponse); }); using (var serverData = ServerUtilities.CreateServer(compilerHost: host)) { var compileTask = ServerUtilities.Send(serverData.PipeName, EmptyServerRequest); // Wait for the request to go through and trigger compilation. await startCompilationSource.Task; // Act for (var i = 0; i < 10; i++) { // The compilation is now in progress, send the shutdown. var processId = await ServerUtilities.SendShutdown(serverData.PipeName); Assert.Equal(Process.GetCurrentProcess().Id, processId); Assert.False(compileTask.IsCompleted); } // Now let the task complete. finishCompilationSource.SetResult(true); // Assert var response = await compileTask; Assert.Equal(ServerResponse.ResponseType.Completed, response.Type); Assert.Equal(0, ((CompletedServerResponse)response).ReturnCode); await serverData.Verify(connections : 11, completed : 11); } }