Skip to content

chore: virtual clock for app hang tests - #1931

Draft
bitsandfoxes wants to merge 3 commits into
masterfrom
chore/test-virtual-time
Draft

chore: virtual clock for app hang tests#1931
bitsandfoxes wants to merge 3 commits into
masterfrom
chore/test-virtual-time

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

Instead of having to call sleep_ms and adding timeouts to wait for app hangs to be detected this introduces an abstraction for the clock for unit tests. This can then be expanded to be used in other tests as well.

This also extracts the checking part out of the worker for unit tests. Checking the full worker functionality i.e. scheduling and wake up are a follow up.

#skip-changelog

Comment thread src/sentry_app_hang_monitor.c Outdated
}

void
sentry__app_hang_monitor_check(uint64_t *last_fired_heartbeat_ms)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted for unit test.

Comment on lines +119 to +121
if (!sentry__app_hang_is_active()) {
sentry__mutex_unlock(&g_wait_mutex);
break;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covers race between outer while condition and acquiring g_wait_mutex.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 95affbb. Configure here.


sentry_close();
sentry__app_hang_monitor_set_stackwalk_fn(NULL);
sentry__test_clock_reset();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests race with live worker

Medium Severity

App-hang tests still call sentry_init, which starts the watchdog worker, and then also invoke sentry__app_hang_monitor_check on the test thread after advancing the virtual clock. Each caller keeps its own last_fired_heartbeat_ms, so after SENTRY_APP_HANG_POLL_MS the worker can capture the same hang again, including a concurrent real stackwalk in app_hang_end_to_end.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 95affbb. Configure here.

Comment thread tests/unit/test_app_hang.c Outdated
sentry__mutex_unlock(&spinner_lock);
TEST_ASSERT(spinner_started);

sentry__test_clock_advance(1000);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes revolve around this. No more sleeping and waiting something is finished spinning up, or waking up. Allows for deterministic testing.

@bitsandfoxes
bitsandfoxes marked this pull request as draft July 30, 2026 13:29
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.77%. Comparing base (e3c769f) to head (f8ed06f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1931      +/-   ##
==========================================
- Coverage   75.79%   75.77%   -0.02%     
==========================================
  Files          93       93              
  Lines       22125    22170      +45     
  Branches     3939     3945       +6     
==========================================
+ Hits        16770    16800      +30     
- Misses       4472     4486      +14     
- Partials      883      884       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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