Test dello scheduler: giudica la lettura che ha visto #185

Merged
Alby96 merged 1 commits from flaky-scheduler-test into main 2026-12-03 21:19:17 +01:00
Owner

Il problema

Nella CI della Fase 10 (corsa 586, PR #184) SchedulerTests.LoopWaitsOnTheInjectedClock è fallito una volta in 38 ms. La sua attesa dura fino a 5 secondi, quindi non era una macchina lenta.

La causa

WaitUntil leggeva la condizione due volte:

  • una nel ciclo;
  • un'altra per l'asserzione.

Il primo giro dello scheduler registra un'attesa sull'orologio e la toglie subito. Lo fa perché il lavoro aggiunto prima di RunAsync ha già segnalato un cambiamento. Così clock.Waiting vale 1 per un istante:

  • il ciclo vedeva 1 e usciva;
  • l'asserzione rileggeva, vedeva 0 e falliva.

Lo scheduler non ha difetti: il giro in più è innocuo.

La correzione

  • WaitUntil giudica la lettura che ha visto.
  • Nuovo test AStateSeenOnceIsEnoughForTheWait: una condizione vera solo alla seconda lettura. È deterministico, senza tempi.

Prove

  • Riproduzione con un test temporaneo, non incluso, che fa girare LoopWaitsOnTheInjectedClock 3.000 volte in parallelo:
    • prima della correzione: 20 fallimenti, tutti «condizione non raggiunta in tempo»;
    • dopo la correzione: 0 fallimenti su 18.000 esecuzioni (6 serie da 3.000).
  • Con il vecchio WaitUntil rimesso apposta, il nuovo test fallisce.
  • ./tasks.ps1 check verde nel hook di commit: 692 test.
  • Gli helper WaitForAsync di OkxTests e TelegramTests leggono la condizione una sola volta per giro: non hanno lo stesso difetto.

🤖 Generated with Claude Code

## Il problema Nella CI della Fase 10 (corsa 586, PR #184) `SchedulerTests.LoopWaitsOnTheInjectedClock` è fallito una volta in 38 ms. La sua attesa dura fino a 5 secondi, quindi non era una macchina lenta. ## La causa `WaitUntil` leggeva la condizione due volte: - una nel ciclo; - un'altra per l'asserzione. Il primo giro dello scheduler registra un'attesa sull'orologio e la toglie subito. Lo fa perché il lavoro aggiunto prima di `RunAsync` ha già segnalato un cambiamento. Così `clock.Waiting` vale 1 per un istante: - il ciclo vedeva 1 e usciva; - l'asserzione rileggeva, vedeva 0 e falliva. Lo scheduler non ha difetti: il giro in più è innocuo. ## La correzione - `WaitUntil` giudica la lettura che ha visto. - Nuovo test `AStateSeenOnceIsEnoughForTheWait`: una condizione vera solo alla seconda lettura. È deterministico, senza tempi. ## Prove - Riproduzione con un test temporaneo, non incluso, che fa girare `LoopWaitsOnTheInjectedClock` 3.000 volte in parallelo: - prima della correzione: 20 fallimenti, tutti «condizione non raggiunta in tempo»; - dopo la correzione: 0 fallimenti su 18.000 esecuzioni (6 serie da 3.000). - Con il vecchio `WaitUntil` rimesso apposta, il nuovo test fallisce. - `./tasks.ps1 check` verde nel hook di commit: 692 test. - Gli helper `WaitForAsync` di `OkxTests` e `TelegramTests` leggono la condizione una sola volta per giro: non hanno lo stesso difetto. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Alby96 added 1 commit 2026-12-03 20:54:02 +01:00
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
1f0c4b322f
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>
Alby96 merged commit ed22d1c8b5 into main 2026-12-03 21:19:17 +01:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: BalboSoft/Anubis#185