test: pass TestContext.Current.CancellationToken at xUnit1051 call sites (analyzer code fix, 451 sites) (lmxopcua#725)
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+11
-11
@@ -215,7 +215,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
eng.OnEvent += (_, e) => events.Add(e);
|
||||
|
||||
up.Push("Temp", 150);
|
||||
await Task.Delay(200);
|
||||
await Task.Delay(200, TestContext.Current.CancellationToken);
|
||||
|
||||
events.Any(e => e.Emission == EmissionKind.Activated).ShouldBeFalse(
|
||||
"OneShot shelve suppresses activation emission");
|
||||
@@ -252,7 +252,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
|
||||
await eng.DisableAsync("HighTemp", "alice", TestContext.Current.CancellationToken);
|
||||
up.Push("Temp", 150);
|
||||
await Task.Delay(100);
|
||||
await Task.Delay(100, TestContext.Current.CancellationToken);
|
||||
eng.GetState("HighTemp")!.Active.ShouldBe(AlarmActiveState.Inactive,
|
||||
"disabled alarm ignores predicate");
|
||||
|
||||
@@ -353,7 +353,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
up.Push($"Temp{round % alarmCount}", round % 2 == 0 ? 150 : 50);
|
||||
round++;
|
||||
}
|
||||
});
|
||||
}, TestContext.Current.CancellationToken);
|
||||
|
||||
// Readers: continuously touch the three unguarded read paths.
|
||||
var readers = Enumerable.Range(0, 4).Select(_reader => Task.Run(() =>
|
||||
@@ -839,7 +839,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
|
||||
// Dispose must wait for the in-flight reevaluation to complete rather
|
||||
// than returning while a background task still runs.
|
||||
var disposeTask = Task.Run(() => eng.Dispose());
|
||||
var disposeTask = Task.Run(() => eng.Dispose(), TestContext.Current.CancellationToken);
|
||||
|
||||
// Verify Dispose does NOT complete immediately — it should block waiting
|
||||
// for the in-flight task. Without the -006 fix Dispose returns straight
|
||||
@@ -1003,7 +1003,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
// load could keep firing between the failed second load and Dispose.
|
||||
// After the fix, it is stopped at the START of every LoadAsync attempt
|
||||
// (successful or not), so Dispose always finds a clean timer state.
|
||||
var disposeTask = Task.Run(() => eng.Dispose());
|
||||
var disposeTask = Task.Run(() => eng.Dispose(), TestContext.Current.CancellationToken);
|
||||
await disposeTask.WaitAsync(TimeSpan.FromSeconds(3), TestContext.Current.CancellationToken);
|
||||
// If Dispose threw or hung, the WaitAsync would surface it.
|
||||
}
|
||||
@@ -1748,12 +1748,12 @@ public sealed class ScriptedAlarmEngineTests
|
||||
eng.TrackBackgroundTaskForTest(() => gate.Task);
|
||||
eng.InFlightCountForTest.ShouldBe(1);
|
||||
|
||||
var disposeTask = Task.Run(() => eng.Dispose());
|
||||
var disposeTask = Task.Run(() => eng.Dispose(), TestContext.Current.CancellationToken);
|
||||
var raced = await Task.WhenAny(disposeTask, Task.Delay(300));
|
||||
raced.ShouldNotBe(disposeTask, "Dispose must not return while registered background work is still running");
|
||||
|
||||
gate.SetResult();
|
||||
await disposeTask.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
await disposeTask.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
eng.InFlightCountForTest.ShouldBe(0, "completed work must unregister itself");
|
||||
}
|
||||
|
||||
@@ -1785,7 +1785,7 @@ public sealed class ScriptedAlarmEngineTests
|
||||
() => throw new InvalidOperationException("factory failed (test)")));
|
||||
|
||||
eng.InFlightCountForTest.ShouldBe(0, "work that never started must not be left registered");
|
||||
await Task.Run(() => eng.Dispose()).WaitAsync(TimeSpan.FromSeconds(5));
|
||||
await Task.Run(() => eng.Dispose(), TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a faulted background task is still drained by Dispose and its failure is
|
||||
@@ -1801,11 +1801,11 @@ public sealed class ScriptedAlarmEngineTests
|
||||
|
||||
// Fault it while Dispose is actually blocked on the drain, so the WhenAll observes
|
||||
// the failure rather than finding an already-unregistered task.
|
||||
var disposeTask = Task.Run(() => Should.NotThrow(() => eng.Dispose()));
|
||||
await Task.Delay(200);
|
||||
var disposeTask = Task.Run(() => Should.NotThrow(() => eng.Dispose()), TestContext.Current.CancellationToken);
|
||||
await Task.Delay(200, TestContext.Current.CancellationToken);
|
||||
gate.SetException(new InvalidOperationException("background failed (test)"));
|
||||
|
||||
await disposeTask.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
await disposeTask.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
||||
eng.InFlightCountForTest.ShouldBe(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user