Wait for the spawner work item in the G5 regression test

Background work items can run concurrently, so the test could read
the disposal task before the spawner item assigned it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roman Ettlinger
2026-09-28 19:36:59 +02:00
parent 7990669e5b
commit 9f52952b2a
@@ -127,17 +127,19 @@ namespace Opc.Ua.Client.Tests.AuditRegressions
var trigger = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using var otherRunning = new ManualResetEventSlim(false);
using var releaseOther = new ManualResetEventSlim(false);
Task disposal = null;
var spawned = new TaskCompletionSource<Task>(TaskCreationOptions.RunContinuationsAsynchronously);
Assert.That(session.RunBackgroundWork("spawner", () =>
{
// Captures the execution context of the work item.
disposal = trigger.Task.ContinueWith(
spawned.SetResult(trigger.Task.ContinueWith(
_ => session.Dispose(),
CancellationToken.None,
TaskContinuationOptions.None,
TaskScheduler.Default);
TaskScheduler.Default));
}), Is.True);
// Background work items may run concurrently; wait until the spawner ran.
Task disposal = await spawned.Task.WaitAsync(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
Assert.That(session.RunBackgroundWork("other", () =>
{
otherRunning.Set();