fix(test): resolve flaky test_midnight_heartbeats boundary condition#157
Conversation
The test was intermittently failing with `assert 9 == 8` because: 1. `midnight` retained residual microseconds from `datetime.now()`, making the exact midnight boundary non-deterministic across runs 2. Event 9 (starting at 23:59 with 1-min duration) has endtime exactly at midnight, and the server's `endtime >= start_query` condition sometimes includes it in the "after midnight" query results Fix: zero out seconds/microseconds on the start timestamp for deterministic boundaries, and add a 1ms offset to the query start to avoid the ambiguous boundary where events ending exactly at midnight could be included. Closes ActivityWatch/activitywatch#1211 (follow-up)
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 7eeec25 in 11 seconds. Click for details.
- Reviewed
31lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_23UrQ42ILyXTdwOr
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile SummaryFixes intermittent test failures in The fix applies two changes:
The root cause was non-deterministic microsecond values from Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 7eeec25 |
|
Fixed Black formatting failure — collapsed the multi-line |
Summary
Fixes the intermittently failing
test_midnight_heartbeatstest (seen in ActivityWatch/activitywatch#1211 CI asassert 9 == 8).Root cause: The test creates events spanning midnight, then queries events "after midnight." Two issues caused non-deterministic results:
midnightretained residual microseconds fromdatetime.now(), making the exact boundary non-deterministic across runsendtimeexactly at midnight, and the server'sendtime >= start_querySQL condition sometimes includes itFix:
>=conditionTest plan
test_midnight_heartbeatspasses consistently (no more flaky failures)Important
Fixes flaky
test_midnight_heartbeatsby ensuring deterministic timestamp boundaries and adding a 1ms offset to avoid boundary ambiguity.test_midnight_heartbeatsintest_client.pyby ensuring deterministic timestamp boundaries.midnightto prevent non-deterministic boundary matching.query_startto avoid including events ending exactly at midnight.test_midnight_heartbeatspasses consistently.This description was created by
for 7eeec25. You can customize this summary. It will automatically update as commits are pushed.