public async Task ClientDisconnectDuringBuild() { using var buildStartedMre = new ManualResetEvent(initialState: false); using var clientClosedMre = new ManualResetEvent(initialState: false); var host = new TestableCompilerServerHost(runCompilation: (request, cancellationToken) => { buildStartedMre.Set(); clientClosedMre.WaitOne(); return(new CompletedBuildResponse(0, utf8output: false, "")); }); using var serverData = await ServerUtil.CreateServer(compilerServerHost : host).ConfigureAwait(false); // Create a short lived client that send a request but does not wait for the using (var client = await BuildServerConnection.TryConnectToServerAsync(serverData.PipeName, Timeout.Infinite, cancellationToken: default).ConfigureAwait(false)) { await s_emptyCSharpBuildRequest.WriteAsync(client).ConfigureAwait(false); await buildStartedMre.WaitOneAsync().ConfigureAwait(false); } clientClosedMre.Set(); var reason = await serverData.ConnectionCompletionCollection.TakeAsync().ConfigureAwait(false); Assert.Equal(CompletionReason.ClientDisconnect, reason); }
public async Task ConnectToPipe() { string pipeName = ServerUtil.GetPipeName(); var oneSec = TimeSpan.FromSeconds(1); Assert.False(await tryConnectToNamedPipe((int)oneSec.TotalMilliseconds, cancellationToken: default)); // Try again with infinite timeout and cancel var cts = new CancellationTokenSource(); var connection = tryConnectToNamedPipe(Timeout.Infinite, cts.Token); Assert.False(connection.IsCompleted); cts.Cancel(); await Assert.ThrowsAnyAsync <OperationCanceledException>( async() => await connection); // Create server and try again using var serverData = CreateServer(pipeName); Assert.True(await tryConnectToNamedPipe(Timeout.Infinite, cancellationToken: default)); async Task <bool> tryConnectToNamedPipe(int timeoutMs, CancellationToken cancellationToken) { using var pipeStream = await BuildServerConnection.TryConnectToServerAsync(pipeName, timeoutMs, _logger, cancellationToken); return(pipeStream != null); } }
public static async Task <bool> TryConnectToNamedPipe(string pipeName, int timeoutMs, CancellationToken cancellationToken) { using (var pipeStream = await BuildServerConnection.TryConnectToServerAsync(pipeName, timeoutMs, cancellationToken)) { return(pipeStream != null); } }
internal async Task <BuildResponse> SendAsync(BuildRequest request, CancellationToken cancellationToken = default) { using var client = await BuildServerConnection.TryConnectToServerAsync(PipeName, Timeout.Infinite, cancellationToken).ConfigureAwait(false); await request.WriteAsync(client).ConfigureAwait(false); return(await BuildResponse.ReadAsync(client).ConfigureAwait(false)); }
internal static async Task <BuildResponse> Send(string pipeName, BuildRequest request) { using (var client = await BuildServerConnection.TryConnectToServerAsync(pipeName, Timeout.Infinite, cancellationToken: default).ConfigureAwait(false)) { await request.WriteAsync(client).ConfigureAwait(false); return(await BuildResponse.ReadAsync(client).ConfigureAwait(false)); } }
private Task <NamedPipeClientStream?> ConnectAsync( CancellationToken cancellationToken = default ) => BuildServerConnection.TryConnectToServerAsync( _host.PipeName, timeoutMs: Timeout.Infinite, logger: _host.Logger, cancellationToken );
protected override async Task <Stream> ConnectForShutdownAsync(string pipeName, int timeout) { return(await BuildServerConnection.TryConnectToServerAsync(pipeName, timeout, cancellationToken : default).ConfigureAwait(false)); }
private Task <NamedPipeClientStream> ConnectAsync(CancellationToken cancellationToken = default) => BuildServerConnection.TryConnectToServerAsync( _host.PipeName, timeoutMs: (int)(TimeSpan.FromMinutes(1).TotalMilliseconds), cancellationToken);