Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
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
6 changes: 4 additions & 2 deletions src/System.IO.Pipelines/tests/FlushAsyncCancellationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,20 @@ public void ReadAsyncCompletesIfFlushAsyncCanceledMidFlush()
var readTask = Pipe.Reader.ReadAsync();

// Signal writer to initiate a flush
if (!readTask.IsCompleted)
if (!readTask.IsCompleted || readTask.Result.IsCompleted)
{
resetEvent.Set();
}

var result = await readTask;
resetEvent.Reset();

if (result.Buffer.IsEmpty)
{
return;
}

resetEvent.Reset();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why this re-ordering was necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So resetEvent is Set when reader completes so canceller doesn't block on WaitOne.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So resetEvent is Set when reader completes

Do you mean Reset? And why not move it to the very end of the loop (after the call to AdvanceTo)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean Set. So canceller can loop and exit.


Pipe.Reader.AdvanceTo(result.Buffer.End);
}
});
Expand All @@ -394,6 +395,7 @@ public void ReadAsyncCompletesIfFlushAsyncCanceledMidFlush()
{
while (!writer.IsCompleted)
{
resetEvent.WaitOne();
cancellationTokenSource.Cancel();
}
});
Expand Down