Syncronize cancellation in ReadAsyncCompletesIfFlushAsyncCanceledMidFlush (dotnet...
authorPavel Krymets <pavel@krymets.com>
Wed, 25 Jul 2018 22:07:05 +0000 (15:07 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Jul 2018 22:07:05 +0000 (15:07 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/dd4a30881d8c0979c65cba7bfdf1f3ab27b3f79b

src/libraries/System.IO.Pipelines/tests/FlushAsyncCancellationTests.cs

index 7894e13..3c8af32 100644 (file)
@@ -373,19 +373,20 @@ namespace System.IO.Pipelines.Tests
                     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();
+
                     Pipe.Reader.AdvanceTo(result.Buffer.End);
                 }
             });
@@ -394,6 +395,7 @@ namespace System.IO.Pipelines.Tests
             {
                 while (!writer.IsCompleted)
                 {
+                    resetEvent.WaitOne();
                     cancellationTokenSource.Cancel();
                 }
             });