Conversation
The shared base-service clock exposed `NowUTC`, `NowUTCOrNil`, and `StubNowUTC`, but those names overstated what the production path was actually doing. The unstubbable implementation already returned `time.Now()` rather than normalizing through `UTC()`, so the API was implying a UTC guarantee that callers were not actually getting. Rename the clock APIs to `Now`, `NowOrNil`, and `StubNow` so the abstraction matches its real job: providing a process-local clock for deadline and duration math, plus an optional stubbed wall-clock value for database-facing test paths. This also makes the monotonic-clock constraint explicit in the documentation. If the production implementation were changed to normalize through `UTC()`, it would strip Go's monotonic reading and make the API a bad fit for in-process elapsed-time calculations.
Make the unstubbed fallback path in `riversharedtest.TimeStub` return `time.Now()` so tests exercise the same non-UTC, monotonic-preserving semantics as the production clock. Update the matching base-service test expectation accordingly.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
After opening #1213 I thought it'd be better to instead fix the underlying time API.
The shared
baseserviceclock exposedNowUTC,NowUTCOrNil, andStubNowUTC, but those names overstated what the production path was actually doing. The unstubbable implementation already returnedtime.Now()rather than normalizing throughUTC(), so the API was implying a UTC guarantee that callers were not actually getting. This renames the clock APIs toNow,NowOrNil, andStubNowso the abstraction matches its real job: providing a process-local clock for deadline and duration math, plus an optional stubbed wall-clock value for database-facing test paths.This also makes the monotonic-clock compatibility explicit in the documentation. If the production implementation were changed to normalize through
UTC(), it would strip Go’s monotonic reading and make the API a bad fit for in-process elapsed-time calculations. The relevant Go documentation is here: Monotonic Clocks in thetimepackage:Fortunately we weren't actually relying on the UTC behavior since it wasn't being applied in prod, so it's an easy switch. Only two small test updates were needed beyond the simple bulk renames.