From 28283636b4279a7f942c4f874597ed686b11e11d Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:52:10 +0000 Subject: [PATCH] test(monitor): Stop background health checks in tests that drive the monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The monitor tests call monitor.run() by hand and assert exact downsample_factor values, but they also set monitor.interval = 0.1, so the monitor's background thread runs extra health checks every 0.1 s. On a slow runner that bumps the factor between the asserts (0.25 instead of 0.5). Kill the background loop in these tests instead. Fixes #8031 Co-Authored-By: Johannes Daxböck --- tests/test_monitor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 96902abca2..f652aab9ca 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -48,7 +48,10 @@ def test_monitor_unhealthy(sentry_init): sentry_init(transport=UnhealthyTestTransport()) monitor = sentry_sdk.get_client().monitor - monitor.interval = 0.1 + # This test calls monitor.run() itself. Stop the background thread + # from running health checks too, or it can bump downsample_factor + # between our asserts on a slow runner (#8031). + monitor.kill() assert monitor.is_healthy() is True @@ -69,7 +72,10 @@ def test_transaction_uses_downsampled_rate( record_lost_event_calls = capture_record_lost_event_calls() monitor = sentry_sdk.get_client().monitor - monitor.interval = 0.1 + # This test calls monitor.run() itself. Stop the background thread + # from running health checks too, or it can bump downsample_factor + # between our asserts on a slow runner (#8031). + monitor.kill() assert monitor.is_healthy() is True monitor.run() @@ -102,7 +108,10 @@ def test_segment_uses_downsampled_rate( record_lost_event_calls = capture_record_lost_event_calls() monitor = sentry_sdk.get_client().monitor - monitor.interval = 0.1 + # This test calls monitor.run() itself. Stop the background thread + # from running health checks too, or it can bump downsample_factor + # between our asserts on a slow runner (#8031). + monitor.kill() assert monitor.is_healthy() is True monitor.run()