Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 72059f6

Browse files
committed
Merge pull request #2823 from stephentoub/fix_unobserved_exception_task_test
Fix Task test causing CI failures
2 parents 57c2b44 + 8d2cd16 commit 72059f6

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/System.Threading.Tasks/tests/System.Runtime.CompilerServices/AsyncTaskMethodBuilderTests.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,22 +434,16 @@ public static void RunAsyncAdditionalBehaviorsTests_NegativeCases2()
434434
cts.Cancel();
435435
b.SignalAndWait(); // release task to complete
436436

437-
// A TCS task
438-
var tcs = new TaskCompletionSource<int>();
439-
tcs.SetCanceled();
440-
Task t2 = tcs.Task;
441-
442-
EventHandler<UnobservedTaskExceptionEventArgs> handler = (s, e) =>
443-
{
444-
Assert.True(false, string.Format(" > OCE shouldn't have resulted in unobserved event firing with " + e.Exception.ToString()));
445-
};
437+
// This test may be run concurrently with other tests in the suite,
438+
// which can be problematic as TaskScheduler.UnobservedTaskException
439+
// is global state. The handler is carefully written to be non-problematic
440+
// if it happens to be set during the execution of another test that has
441+
// an unobserved exception.
442+
EventHandler<UnobservedTaskExceptionEventArgs> handler =
443+
(s, e) => Assert.DoesNotContain(oce, e.Exception.InnerExceptions);
446444
TaskScheduler.UnobservedTaskException += handler;
447-
448445
((IAsyncResult)t1).AsyncWaitHandle.WaitOne();
449-
((IAsyncResult)t2).AsyncWaitHandle.WaitOne();
450446
t1 = null;
451-
t2 = null;
452-
453447
for (int i = 0; i < 10; i++)
454448
{
455449
GC.Collect();

0 commit comments

Comments
 (0)