Skip to content

Fix flaky testWeeklyIsSessionTimePeriodically in SessionScheduleTest - #1317

Merged
chrjohn merged 3 commits into
masterfrom
copilot/fix-session-schedule-test-failure
Sep 4, 2026
Merged

Fix flaky testWeeklyIsSessionTimePeriodically in SessionScheduleTest#1317
chrjohn merged 3 commits into
masterfrom
copilot/fix-session-schedule-test-failure

Conversation

Copilot AI commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

SessionScheduleTest.testWeeklyIsSessionTimePeriodically intermittently failed CI with wrong end time expected, most notably on windows-latest runners.

Root cause

  • DefaultSessionSchedule computes session interval boundaries with MILLISECOND always zeroed, and treats the interval end as inclusive (t.compareTo(end) <= 0).
  • The test seeds its expected Calendar from the real wall clock but never resets MILLISECOND, so it retains whatever fractional millisecond happened to be present at test start.
  • When that leftover millisecond is non-zero (the common case), "now" ends up just past the zeroed end boundary at the expected tick, so the transition out of the session is detected on time — working by coincidence.
  • When the real wall-clock millisecond is exactly 0, "now" equals the inclusive end boundary instead of exceeding it, delaying detection of the session-end transition by one full polling increment (5s) and failing the assertion.
  • Windows' coarser clock quantization (~15.625 ms, an exact divisor of 1000 ms) makes landing on millisecond 0 far more likely than on higher-resolution Linux/macOS clocks, explaining the platform-specific flakiness.

Fix

  • Pin the test's seed Calendar to a fixed non-zero MILLISECOND value instead of leaving it dependent on the real clock, removing the dependency on wall-clock luck while preserving the test's original intent.
c.set(Calendar.SECOND, 0);
// Fix the millisecond to a non-zero value so this test is deterministic regardless
// of the real wall-clock time when it starts (see DefaultSessionSchedule's
// inclusive, millisecond-zeroed interval end).
c.set(Calendar.MILLISECOND, 1);
mockSystemTimeSource.setTime(c);

No production code changes were needed — this is a test-only fix.

Co-authored-by: chrjohn <6644028+chrjohn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job for SessionScheduleTest Fix flaky testWeeklyIsSessionTimePeriodically in SessionScheduleTest Sep 4, 2026
Copilot AI requested a review from chrjohn September 4, 2026 10:51
@chrjohn chrjohn changed the title Fix flaky testWeeklyIsSessionTimePeriodically in SessionScheduleTest Fix flaky testWeeklyIsSessionTimePeriodically in SessionScheduleTest Sep 4, 2026
@chrjohn chrjohn added this to the QFJ 3.0.3 milestone Sep 4, 2026
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.42%. Comparing base (68d7124) to head (c879235).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1317      +/-   ##
============================================
+ Coverage     70.40%   70.42%   +0.02%     
  Complexity     2248     2248              
============================================
  Files           159      159              
  Lines          9065     9065              
  Branches       1192     1192              
============================================
+ Hits           6382     6384       +2     
+ Misses         2218     2216       -2     
  Partials        465      465              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chrjohn

chrjohn commented Sep 4, 2026

Copy link
Copy Markdown
Member

@copilot codecov is failing. Can you improve test coverage for your added code?

Co-authored-by: chrjohn <6644028+chrjohn@users.noreply.github.com>

Copilot AI commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot codecov is failing. Can you improve test coverage for your added code?

The codecov/patch check was already green (100% of the diff covered); the codecov/project drop was because the fix removed the only path that exercised the inclusive end-boundary branch in DefaultSessionSchedule.TimeInterval.isContainingTime (previously hit only by chance when the wall-clock millisecond was 0). Added testWeeklyIsSessionTimeInclusiveAtEndBoundary, which deterministically asserts that branch (true exactly at the end time, false one ms later) - see latest commit.

@chrjohn
chrjohn marked this pull request as ready for review September 4, 2026 16:12
@chrjohn
chrjohn merged commit e1c07e9 into master Sep 4, 2026
14 checks passed
@chrjohn
chrjohn deleted the copilot/fix-session-schedule-test-failure branch September 4, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants