public async Task UseExistingServer() { using var serverData = await ServerUtil.CreateServer(Logger); var ran = false; var workingDirectory = TempRoot.CreateDirectory().Path; for (var i = 0; i < 5; i++) { var response = await BuildServerConnection.RunServerBuildRequestAsync( ProtocolUtil.CreateEmptyCSharp(workingDirectory), serverData.PipeName, timeoutOverride : Timeout.Infinite, tryCreateServerFunc : (_, _) => { ran = true; return(false); }, Logger, cancellationToken : default); Assert.True(response is CompletedBuildResponse); } Assert.False(ran); }
public async Task OnlyStartOneServer() { ServerData?serverData = null; try { var pipeName = ServerUtil.GetPipeName(); var workingDirectory = TempRoot.CreateDirectory().Path; for (var i = 0; i < 5; i++) { var response = await BuildServerConnection.RunServerBuildRequestAsync( ProtocolUtil.CreateEmptyCSharp(workingDirectory), pipeName, timeoutOverride : Timeout.Infinite, tryCreateServerFunc : (pipeName, logger) => { Assert.Null(serverData); serverData = ServerData.Create(logger, pipeName); return(true); }, Logger, cancellationToken : default); Assert.True(response is CompletedBuildResponse); } } finally { serverData?.Dispose(); } }
public async Task FailedServer() { var pipeName = ServerUtil.GetPipeName(); var workingDirectory = TempRoot.CreateDirectory().Path; var count = 0; for (var i = 0; i < 5; i++) { var response = await BuildServerConnection.RunServerBuildRequestAsync( ProtocolUtil.CreateEmptyCSharp(workingDirectory), pipeName, timeoutOverride : Timeout.Infinite, tryCreateServerFunc : (_, _) => { count++; return(false); }, Logger, cancellationToken : default); Assert.True(response is RejectedBuildResponse); } Assert.Equal(5, count); }
internal Task <BuildResponse> SendAsync(BuildRequest request, CancellationToken cancellationToken = default) => BuildServerConnection.RunServerBuildRequestAsync( request, PipeName, timeoutOverride: Timeout.Infinite, tryCreateServerFunc: (_, _) => false, Logger, cancellationToken);
internal static BuildClient CreateBuildClient( RequestLanguage language, ICompilerServerLogger logger) { // Create a client to run the build. Infinite timeout is used to account for the // case where these tests are run under extreme load. In high load scenarios the // client will correctly drop down to a local compilation if the server doesn't respond // fast enough. CompileOnServerFunc compileOnServerFunc = (request, pipeName, cancellationToken) => BuildServerConnection.RunServerBuildRequestAsync( request, pipeName, timeoutOverride: Timeout.Infinite, tryCreateServerFunc: (_, _) => false, logger, cancellationToken); var compileFunc = GetCompileFunc(language); return(new BuildClient(language, compileFunc, compileOnServerFunc)); }
public async Task SimulateServerCrashingOnStartup() { var pipeName = ServerUtil.GetPipeName(); var ran = false; var response = await BuildServerConnection.RunServerBuildRequestAsync( ProtocolUtil.CreateEmptyCSharp(TempRoot.CreateDirectory().Path), pipeName, timeoutOverride : (int)TimeSpan.FromSeconds(2).TotalMilliseconds, tryCreateServerFunc : (_, _) => { ran = true; // Correct this is a lie. The server did not start. But it also does a nice // job of simulating a hung or crashed server. return(true); }, Logger, cancellationToken : default); Assert.True(response is RejectedBuildResponse); Assert.True(ran); }
internal int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands, ICompilerServerLogger logger) { if (ProvideCommandLineArgs) { CommandLineArgs = GetArguments(commandLineCommands, responseFileCommands) .Select(arg => new TaskItem(arg)).ToArray(); } if (SkipCompilerExecution) { return(0); } try { var requestId = Guid.NewGuid(); logger.Log($"Compilation request {requestId}, PathToTool={pathToTool}"); string workingDirectory = CurrentDirectoryToUse(); string?tempDirectory = BuildServerConnection.GetTempPath(workingDirectory); if (!UseSharedCompilation || HasToolBeenOverridden || !BuildServerConnection.IsCompilerServerSupported) { LogCompilationMessage(logger, requestId, CompilationKind.Tool, $"using command line tool by design '{pathToTool}'"); return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)); } _sharedCompileCts = new CancellationTokenSource(); logger.Log($"CommandLine = '{commandLineCommands}'"); logger.Log($"BuildResponseFile = '{responseFileCommands}'"); var clientDirectory = Path.GetDirectoryName(PathToManagedTool); if (clientDirectory is null || tempDirectory is null) { LogCompilationMessage(logger, requestId, CompilationKind.Tool, $"using command line tool because we could not find client or temp directory '{PathToManagedTool}'"); return(base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands)); } // Note: using ToolArguments here (the property) since // commandLineCommands (the parameter) may have been mucked with // (to support using the dotnet cli) var buildRequest = BuildServerConnection.CreateBuildRequest( requestId, Language, GetArguments(ToolArguments, responseFileCommands).ToList(), workingDirectory: workingDirectory, tempDirectory: tempDirectory, keepAlive: null, libDirectory: LibDirectoryToUse()); var pipeName = !string.IsNullOrEmpty(SharedCompilationId) ? SharedCompilationId : BuildServerConnection.GetPipeName(clientDirectory); var responseTask = BuildServerConnection.RunServerBuildRequestAsync( buildRequest, pipeName, clientDirectory, logger: logger, cancellationToken: _sharedCompileCts.Token); responseTask.Wait(_sharedCompileCts.Token); ExitCode = HandleResponse(requestId, responseTask.Result, pathToTool, responseFileCommands, commandLineCommands, logger); } catch (OperationCanceledException) { ExitCode = 0; } catch (Exception e) { Log.LogErrorWithCodeFromResources("Compiler_UnexpectedException"); Log.LogErrorFromException(e); ExitCode = -1; } finally { _sharedCompileCts?.Dispose(); _sharedCompileCts = null; } return(ExitCode); }