Repository navigation
Test helper: Elapse holds at least the time it is given - #6708
Merged
Merged
Conversation
erikdarlingdata
marked this pull request as ready for review
October 24, 2026 09:55
There was a problem hiding this comment.
Verdict: LGTM
Claims
- VERIFIED —
Elapsenow waits again for whatever time is left, measured withTimeProvider.System, until the full duration has passed — matches the diff:Darling/Darling.Tests/TestTimeHelpers.cs:65-74, theforloop recomputingleftfromGetElapsedTime(started)on each pass. - VERIFIED — the diff is 10 insertions and 1 deletion in that one file —
gh pr view 6708reportsadditions: 10, deletions: 1, andgh pr diff 6708 --name-onlyshows the single file. - VERIFIED — Lite.Tests has no
Elapseof its own and compiles this same file through a link —Lite.Tests/Lite.Tests.csproj:77:<Compile Include="..\Darling\Darling.Tests\TestTimeHelpers.cs" Link="TestTimeHelpers.cs" />. - VERIFIED —
WaitCorealready re-reads the clock on every pass and is not changed by this diff — confirmed by the diff hunk (no change toWaitCore,TestTimeHelpers.cs:77-100) and its own re-entrant loop readingelapsed()each iteration. - VERIFIED — a zero duration returns at once, as before — the new loop's condition
left > TimeSpan.Zerois false on entry forduration == TimeSpan.Zero, soPauseis never called, same net effect (no wait) as the oldPause(TimeSpan.Zero). - VERIFIED — a negative duration now returns at once, where before it threw (or waited forever for exactly -1 ms) — same reasoning:
left > TimeSpan.Zerois false for any negativeduration, so the loop body — and the exceptionManualResetEventSlim.Waitwould have thrown for most negative values — never runs. - VERIFIED — no caller passes a negative value — grepped every
Elapse(call site (InstallIdStoreTests.cs:194,StaTestThread.cs:365vias_sampleWindow = TimeSpan.FromMilliseconds(250),ReadWindowBandTests.cs:179,ManagedConfFileTests.cs:788,DarlingPasswordKeyStoreLiveTests.cs:523,ClipboardTextRetryBudgetTests.cs:217); all are positive literals. - UNVERIFIED — the specific CI failure numbers from PR #6704 (
Assert.InRange(scope.Scope.WaitMs, 50, 4_000)got 47 afterElapse(TimeSpan.FromMilliseconds(60))) — a live CI run's log, not checkable from this read-only tree.
Riskiest lines
Darling/Darling.Tests/TestTimeHelpers.cs:70— the recomputedleftdrives every subsequentPause; if it undercounted elapsed time the loop could return early again, reproducing the exact bug being fixed — no behaviour test covers it (see below) | UNCOVEREDDarling/Darling.Tests/TestTimeHelpers.cs:66-74— a pathological early-return pattern from the OS timer could in principle spin many iterations before the remaining time shrinks to zero; not a hang (wall-clock time is monotonic and strictly advancesGetElapsedTime), just a possible brief tight loop at the tail — UNCOVEREDDarling/Darling.Tests/TestTimeHelpers.cs:65— the removed one-linePause(duration)is now multi-statement; any caller relying onElapsereturning in bounded/short real time (e.g., a CI timeout) would be affected by the loop running longer under a very coarse timer — all six call sites use small literal durations (≤2.7 s), so this is low risk | UNCOVERED
Traps near this diff
- "A test that reads the clock twice measures the CI scheduler: the delta-seeder tests failed at 123 and 243 on unrelated PRs (#3676). One anchor owns both ends of an interval." — does not apply:
Elapsetakes onestartedtimestamp viaGetTimestamp()and repeatedly measures elapsed time FROM that single anchor viaGetElapsedTime(started)(TestTimeHelpers.cs:69-70); it never takes a second independent anchor, so this is the same single-anchor patternWaitUntil/TryWaitUntilalready use, not the double-read shape the trap warns about. - "Lite and Darling ship in parity... a fix to one SKU's reader... without the counterpart's is a finding." — does not apply: this is one physical file, linked into both
Darling.TestsandLite.Tests(Lite.Tests.csproj:77), so there is no counterpart to miss — the single edit reaches both SKUs' test runs.
Divergence (blind read vs PR body)
None — the body's account matches the diff on every claim graded above, including the negative-duration behaviour change, which the body discloses itself ("A negative duration now returns at once. Before, it threw ArgumentOutOfRangeException, or for -1 ms waited forever. No caller passes a negative value.") and which I independently derived from the loop condition before reading the body.
Reviewer checklist
- Confirm CI (Guard stage plus the named test classes:
ClipboardTextRetryBudgetTests,DarlingPasswordKeyStoreLiveTests,ManagedConfFileTests,ReadWindowBandTests,StaTestThread,InstallIdStoreTests) actually goes green on a real Windows runner, since this fix targets a timer-granularity effect that can't be forced deterministically in a read-only review.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude posting for Erik Darling.
No issue.
Why
CI failed on PR #6704 in
Darling.Tests.ReadScopeCapacityTests.OnPending_MeasuresTheWaitInsideAScope_AndACreateInsideItIsNotAddedTwice:Assert.InRange(scope.Scope.WaitMs, 50, 4_000)got 47 afterTestWait.Elapse(TimeSpan.FromMilliseconds(60)). The product measures the wait withStopwatch(ReadConnectionWait.cs:80,91), so the test's input was shorter than the test asked for. That failure is unrelated to #6704's change.TestWait.Elapsewas one timed wait on a never-setManualResetEventSlim. On Windows a timed wait can return up to one timer tick (about 15.6 ms) early, so a single wait can hold for less than the duration it is given.What changes
Darling/Darling.Tests/TestTimeHelpers.cs:Elapsenow waits again for whatever time is left, measured withTimeProvider.System, until the full duration has passed. It holds for at least the duration it is given. The diff is 10 insertions and 1 deletion in that one file.Elapseof its own. It compiles this same file through a link (Lite.Tests/Lite.Tests.csproj:77), so the one edit covers both projects.WaitCore(behindWaitUntilandTryWaitUntil) already re-reads the clock on every pass, so an early return only adds a pass there. It is not changed.Behaviour notes:
ArgumentOutOfRangeException, or for -1 ms waited forever. No caller passes a negative value.Test plan
Elapse(:ClipboardTextRetryBudgetTests,DarlingPasswordKeyStoreLiveTests,ManagedConfFileTests,ReadWindowBandTestsandStaTestThread(Darling), andInstallIdStoreTests(Lite).Considered, not added
ReadScopeCapacityTests, which is not on dev.Pause. That would change theWaitUntilpath too, andWaitCorealready tolerates an early return. OnlyElapseneeds the floor.For the coordinator
TimeProvider.System.GetTimestampandGetElapsedTime, both already used in the same file.