Skip to content

Fix Heartbeat Test Runs before 9am UTC#1139

Open
matmanna wants to merge 3 commits intohackclub:mainfrom
matmanna:test-issues
Open

Fix Heartbeat Test Runs before 9am UTC#1139
matmanna wants to merge 3 commits intohackclub:mainfrom
matmanna:test-issues

Conversation

@matmanna
Copy link
Copy Markdown
Member

@matmanna matmanna commented Apr 6, 2026

ts should make the tests for #1138 pass

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 6, 2026

Greptile Summary

This PR fixes a flaky test that failed when run before 9am UTC. The daily_streaks_for_users query filters heartbeats with .where(time: start_date..Time.current), so heartbeats created at beginning_of_day + 9.hours were excluded from results when the wall-clock time was earlier than 9am. Wrapping the test body in travel_to(Time.utc(2026, 1, 1, 12, 0, 0)) pins time to noon UTC, ensuring the 9am heartbeats always fall within the query window.

Confidence Score: 5/5

Safe to merge — test-only change with a correct, targeted fix for a timing-dependent flake.

No production code is changed. The fix correctly pins time to noon UTC using the standard Rails travel_to helper, ensuring heartbeats at 9am UTC always fall within the daily_streaks_for_users query window (start_date..Time.current). No P0 or P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
test/models/heartbeat_test.rb Wraps time-sensitive test in travel_to(noon UTC) to prevent failures when tests run before 9am UTC

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Test runs at real clock time T] --> B{Is T before 9am UTC?}
    B -- Yes --> C[beginning_of_day + 9h is a future timestamp]
    C --> D[daily_streaks_for_users filters time up to Time.current]
    D --> E[Heartbeat excluded from query window]
    E --> F[streak = 0 — assertion fails]
    B -- No --> G[beginning_of_day + 9h is a past timestamp]
    G --> H[Heartbeat included in query window]
    H --> I[streak = 1 — test passes]
    J[Fix: travel_to noon UTC] --> G
Loading

Reviews (1): Last reviewed commit: "fix: heatrbeat test 9am issue" | Re-trigger Greptile

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.

1 participant