Judge the scheduler test on the reading it saw
ci / test (postgres) (push) Successful in 6m6s
ci / test (sqlite) (push) Successful in 4m57s
ci / test (postgres) (pull_request) Successful in 5m59s
ci / test (sqlite) (pull_request) Successful in 4m49s
ci / image (push) Successful in 1m37s
ci / image (pull_request) Successful in 53s
ci / test (postgres) (push) Successful in 6m6s
ci / test (sqlite) (push) Successful in 4m57s
ci / test (postgres) (pull_request) Successful in 5m59s
ci / test (sqlite) (pull_request) Successful in 4m49s
ci / image (push) Successful in 1m37s
ci / image (pull_request) Successful in 53s
LoopWaitsOnTheInjectedClock failed once on the CI (run 586) in 38 ms, although its wait lasts up to five seconds. WaitUntil read the condition in its loop and then read it again for the assertion. The scheduler's first round registers a wait on the clock and drops it at once, because the job added before RunAsync has already signalled a change, so the loop could see the clock waited on and the assertion could see it no longer waited on. The test run 3,000 times in parallel failed 20 times before the fix and never in 18,000 runs after it. WaitUntil now judges the reading it saw, and AStateSeenOnceIsEnoughForTheWait, which fails with the old helper, keeps it that way. The scheduler itself is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1bc7e067fd
commit
1f0c4b322f
1 file changed
+17
-2
@@ -288,13 +288,28 @@ public sealed class SchedulerTests
|
|||||||
await Assert.ThrowsAsync<OperationCanceledException>(() => loop).ConfigureAwait(false);
|
await Assert.ThrowsAsync<OperationCanceledException>(() => loop).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[TestCategory(Category.Unit)]
|
||||||
|
public async Task AStateSeenOnceIsEnoughForTheWait()
|
||||||
|
{
|
||||||
|
// A state that holds for an instant (CI run 586): the wait judges the reading it saw, it does not ask again.
|
||||||
|
var readings = 0;
|
||||||
|
await WaitUntil(() => Interlocked.Increment(ref readings) == 2).ConfigureAwait(false);
|
||||||
|
Assert.AreEqual(2, readings);
|
||||||
|
}
|
||||||
|
|
||||||
internal static async Task WaitUntil(Func<bool> condition)
|
internal static async Task WaitUntil(Func<bool> condition)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < 500 && !condition(); i++)
|
// One reading per round, and the reading seen is the one judged. Asking again for the assertion failed the test
|
||||||
|
// when the state held only for an instant: the scheduler's first round registers a wait on the clock and drops it
|
||||||
|
// at once, because the job added before RunAsync has already signalled a change.
|
||||||
|
var met = condition();
|
||||||
|
for (var i = 0; i < 500 && !met; i++)
|
||||||
{
|
{
|
||||||
await Task.Delay(10).ConfigureAwait(false);
|
await Task.Delay(10).ConfigureAwait(false);
|
||||||
|
met = condition();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsTrue(condition(), "condizione non raggiunta in tempo");
|
Assert.IsTrue(met, "condizione non raggiunta in tempo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user