Skip to content

improve SendFileGetsCanceledByDispose test #79718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all 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 @@ -250,7 +250,6 @@ public async Task SendFileGetsCanceledByDispose(bool owning)
// We try this a couple of times to deal with a timing race: if the Dispose happens
// before the operation is started, the peer won't see a ConnectionReset SocketException and we won't
// see a SocketException either.
int msDelay = 100;
await RetryHelper.ExecuteAsync(async () =>
{
(Socket socket1, Socket socket2) = SocketTestExtensions.CreateConnectedSocketPair();
Expand All @@ -270,9 +269,10 @@ await RetryHelper.ExecuteAsync(async () =>
await SendFileAsync(socket1, tempFile.Path);
});

// Wait a little so the operation is started.
await Task.Delay(msDelay);
msDelay *= 2;
// read one byte to make sure SendFileAsync started
byte[] buffer = new byte[1];
socket2.Receive(buffer);

Task disposeTask = Task.Run(() => socket1.Dispose());

await Task.WhenAny(disposeTask, socketOperation).WaitAsync(TimeSpan.FromSeconds(30));
Expand Down