From: Stephen Toub Date: Wed, 15 Feb 2023 16:13:50 +0000 (-0500) Subject: Fix CancellationTokenSource_CancelAsync_AllCallbacksInvoked test (#82153) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4005 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db6a5f54e5ad61c28f53012bcb896ae226b517a7;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix CancellationTokenSource_CancelAsync_AllCallbacksInvoked test (#82153) If the task internally queued by CancelAsync hasn't started yet by the time we block waiting for it, Wait could inline it and end up running it on the current thread. --- diff --git a/src/libraries/System.Threading.Tasks/tests/CancellationTokenTests.cs b/src/libraries/System.Threading.Tasks/tests/CancellationTokenTests.cs index b1be8a7..4d2c89b 100644 --- a/src/libraries/System.Threading.Tasks/tests/CancellationTokenTests.cs +++ b/src/libraries/System.Threading.Tasks/tests/CancellationTokenTests.cs @@ -1787,7 +1787,9 @@ namespace System.Threading.Tasks.Tests Task t = cts.CancelAsync(); Assert.True(cts.IsCancellationRequested); - t.Wait(); // synchronously block to ensure this thread isn't reused + ((IAsyncResult)t).AsyncWaitHandle.WaitOne(); // synchronously block without inlining to ensure this thread isn't reused + t.Wait(); // propagate any exceptions + Assert.Equal(Iters * (Iters + 1) / 2, sum); }