Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void ConnectInternal(int timeout, CancellationToken cancellationToken, i
cancellationToken.ThrowIfCancellationRequested();

// Determine how long we should wait in this connection attempt
int waitTime = timeout - elapsed;
int waitTime = timeout == Timeout.Infinite ? CancellationCheckInterval : timeout - elapsed;
if (cancellationToken.CanBeCanceled && waitTime > CancellationCheckInterval)
{
waitTime = CancellationCheckInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,31 @@ public async Task ClientConnectAsync_With_Cancellation_Throws_Timeout_When_Pipe_
}
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)] // Unix implementation doesn't rely on a timeout and cancellation token when connecting
public async Task ClientConnectAsync_Cancel_With_InfiniteTimeout()
{
string pipeName = PipeStreamConformanceTests.GetUniquePipeName();

using (var cts = new CancellationTokenSource())
using (var server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1))
using (var firstClient = new NamedPipeClientStream(pipeName))
using (var secondClient = new NamedPipeClientStream(pipeName))
{
var firstConnectionTasks = new Task[]
{
firstClient.ConnectAsync(),
Task.Run(() => server.WaitForConnectionAsync())
};

Assert.True(Task.WaitAll(firstConnectionTasks, 1000));

cts.CancelAfter(100);

await Assert.ThrowsAsync<OperationCanceledException>(() => secondClient.ConnectAsync(cts.Token)).WaitAsync(1000);
}
}

public static IEnumerable<object[]> GetCancellationTokens =>
new []
{
Expand Down