Skip to content

fix TestAppLogs flake with deterministic time mock#3785

Open
ntner wants to merge 1 commit intomasterfrom
fix-applogs-flake
Open

fix TestAppLogs flake with deterministic time mock#3785
ntner wants to merge 1 commit intomasterfrom
fix-applogs-flake

Conversation

@ntner
Copy link
Copy Markdown
Contributor

@ntner ntner commented 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 ntner requested a review from nightfury1204 March 31, 2026 00:20
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.
@ntner ntner mentioned this pull request Mar 31, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant