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

Commit df0c068

Browse files
committed
Fix and enable a disabled Task test
The test was assuming that if all tasks queued to a scheduler have completed that the scheduler won't be making further use of whatever underlying scheduler it's targeting. That assumption is false, however, as the scheduler may still queue additional housekeeping tasks, and it requires that the underlying scheduler remain alive until the overlaying scheduler declares completion via its Completion task.
1 parent cda0ae1 commit df0c068

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

src/System.Threading.Tasks/tests/CESchedulerPairTests.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,8 @@ public static void TestCompletionTask()
420420

421421
/// <summary>
422422
/// Ensure that CESPs can be layered on other CESPs.
423-
/// There is and assert in src\Threading\System\Threading\Tasks\ConcurrentExclusiveSchedulerPair.cs
424-
/// line 355 - the scheduler enters in exclusive processing mode when should not
425-
/// it needs more investigations
426423
/// </summary
427424
[Fact]
428-
[ActiveIssue(2797)]
429425
public static void TestSchedulerNesting()
430426
{
431427
// Create a hierarchical set of scheduler pairs
@@ -490,30 +486,13 @@ public static void TestSchedulerNesting()
490486
}
491487
}
492488

493-
// Once all tasks have completed, complete the schedulers
494-
Task.Factory.StartNew(() =>
495-
{
496-
Debug.WriteLine(string.Format("Waiting for all tasks", tasks.Count));
497-
Task.WaitAll(tasks.ToArray());
498-
foreach (var cesp in cesps) cesp.Complete();
499-
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
500-
501-
// In the meantime, wait for all schedulers to complete
502-
Debug.WriteLine("Waiting for all csps");
503-
foreach (var cesp in cesps) cesp.Completion.Wait();
504-
505-
Debug.WriteLine("Done waiting");
506-
// All tasks should now be done for the schedulers to have completed
507-
foreach (var task in tasks)
489+
// Wait for all tasks to complete, then complete the schedulers
490+
Task.WaitAll(tasks.ToArray());
491+
foreach (var cesp in cesps)
508492
{
509-
if (task.Status != TaskStatus.RanToCompletion)
510-
{
511-
Debug.WriteLine("Task didn't run to completion");
512-
}
493+
cesp.Complete();
494+
cesp.Completion.Wait();
513495
}
514-
515-
// All tasks should now be done for the schedulers to have completed
516-
foreach (var task in tasks) Assert.True(task.Status == TaskStatus.RanToCompletion, "All tasks should now be complete");
517496
}
518497

519498
/// <summary>

0 commit comments

Comments
 (0)