fix TestAppLogs flake with deterministic time mock#3785
Open
Conversation
ntner
added a commit
that referenced
this pull request
Mar 31, 2026
## Summary - Fix flaky `TestAppLogs` by mocking `helpers.TimeNow` for deterministic timing - Uses the exact same pattern already proven in the adjacent `TestAppLogsSince` test ## Details `TestAppLogs` computed its `Since` duration using `time.Since(time.Date(2011, 1, 1, ...))`. By the time `helpers.TimeNow()` was called internally to compute `startTime`, milliseconds had elapsed, so the mock's expected `startTime: 1293840000000` didn't match (e.g., got `1293840000029`). Fix: Mock `helpers.TimeNow` to return a fixed time (2025-04-09T22:00:00Z) before the `StubAwsProvider` call, then compute `Since` deterministically using the mocked time. This is identical to the pattern already used in `TestAppLogsSince` (line 111). The mock cycles expect `startTime: 1293840000000` which is exactly `time.Date(2011,1,1,0,0,0,0,UTC).UnixMilli()`. ## Backward Compatibility Test-only change. No runtime code modified.
ntner
added a commit
that referenced
this pull request
Mar 31, 2026
## Summary - Fix flaky `TestAppLogs` by mocking `helpers.TimeNow` for deterministic timing - Uses the exact same pattern already proven in the adjacent `TestAppLogsSince` test ## Details `TestAppLogs` computed its `Since` duration using `time.Since(time.Date(2011, 1, 1, ...))`. By the time `helpers.TimeNow()` was called internally to compute `startTime`, milliseconds had elapsed, so the mock's expected `startTime: 1293840000000` didn't match (e.g., got `1293840000029`). Fix: Mock `helpers.TimeNow` to return a fixed time (2025-04-09T22:00:00Z) before the `StubAwsProvider` call, then compute `Since` deterministically using the mocked time. This is identical to the pattern already used in `TestAppLogsSince` (line 111). The mock cycles expect `startTime: 1293840000000` which is exactly `time.Date(2011,1,1,0,0,0,0,UTC).UnixMilli()`. ## Backward Compatibility Test-only change. No runtime code modified.
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.
Summary
TestAppLogsby mockinghelpers.TimeNowfor deterministic timingTestAppLogsSincetestDetails
TestAppLogscomputed itsSinceduration usingtime.Since(time.Date(2011, 1, 1, ...)). By the timehelpers.TimeNow()was called internally to computestartTime, milliseconds had elapsed, so the mock's expectedstartTime: 1293840000000didn't match (e.g., got1293840000029).Fix: Mock
helpers.TimeNowto return a fixed time (2025-04-09T22:00:00Z) before theStubAwsProvidercall, then computeSincedeterministically using the mocked time. This is identical to the pattern already used inTestAppLogsSince(line 111).The mock cycles expect
startTime: 1293840000000which is exactlytime.Date(2011,1,1,0,0,0,0,UTC).UnixMilli().Backward Compatibility
Test-only change. No runtime code modified.