Repository navigation
[RT-E2] refactor: the background service runs on an injected TimeProvider - #429
Merged
Merged
Conversation
…-E2 A) IServiceClock and ServiceClock are gone. Discover, Stop and Ensure each choose TimeProvider.System once, as a composition root, and pass it to the info probe, the PTY handoff, the stopper and terminator, the election and the contenders. UTC reads stay UTC at the same read points, and every former CancelAfter is armed at its old point, so no bound moves. New manual-clock tests prove each newly reachable bound (probe, ticket, fallback, election poll, terminator rungs, contender backoff).
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.
What
The background service's delays and bounds now run on an injected
TimeProviderinstead of the system clock. This is RT-E2 PR A of three (B: terminals; C: the launcher and the clock ban).Closes
IServiceClockcovered onlyUtcNow, so every delay and bound in the unit still ran on real time.IServiceClockandServiceClockare deleted.The change
DiscoverAsync,StopAsyncandEnsureAsynceach chooseTimeProvider.Systemonce, with a comment naming the choice. They pass the clock to the info probe, the PTY handoff (ticket and fallback), the stopper and terminator, the election and the contenders. No collaborator has a System fallback. The counted RS0030 pragmas for these roots come with the ban in PR C.expiresAt. Every formerCancelAfteris armed at its old point (probe after headers, ticket after pipeline construction, fallback at entry). The caller, refusal and timeout classification is unchanged.TimedCancellation.Create(TimeSpan, TimeProvider), one internal factory inInternal/Threading. It corrects the approved plan.TimeProvider.System,Microsoft.Bcl.TimeProvider10.0.13'sCreateCancellationTokenSourcecreates a separate timer and disposes it only from a cancellation callback. A deadline disposed before it fires therefore leaves its timer armed.new CancellationTokenSource(timeout, time).ManualTimeProvider(tests) gains one optional start time, so the handoff scenario keeps its fixed clock. Existing callers are unchanged.Proof
CancelAftercalls and 1 UTC adapter read.ManualTimeProvider. Each waits for an entry or armed-timer signal before advancing, and each is killed by a compiling product mutant that removes the bound while keeping the signature, on net10.0 and net472:TimedCancellationTests:ObjectDisposedException.ServiceEnsurerTests,ServiceStopperTests,ServiceInfoProbeTests,OpenCodeServerDiscoveryLiveTests,ServicePtyHandoffScenario,ServiceContenderSpawnerTests,ServiceContenderSpawnerRequestTests,ServiceContenderTests,EnsureServiceContext, ServiceFixtureEnsureModeandDiscoveryMode, andtests/Shared/ContenderLedger.cs.ServiceContenderSpawnerTests' Unix cleanup is reordered (kill, advance, wait forFinished, then disappearance), because the contender is the child's only reaper and its watch now runs on the test clock. The existing clock-racing tests are TST-E2b's and are not rewritten here.ReservedNamePolicy.InternalTypeNamesdropsIServiceClockandServiceClockand addsTimedCancellation.OpenCode.Sdk.Tools.Testsproject 1998/1998; the BackgroundService namespace 515/515 on net10.0 and net472.PublicApi.verified.txtis unchanged.73eb46b1(this branch on masterb7df1975): slopwatch, build, both format passes, clone-detector, verify-clones, 10,408 tests including net472 with 0 failed, and election. An earlier run caught the stale internal type registry, fixed above.Need help on this PR? Tag
@codesmith-botwith what you need.