Skip to content

Commit 24ff045

Browse files
author
cellwebb
committed
test(monitor): improve stuck detection test reliability
- Replace fixed sleep with polling mechanism to handle CI timing variance - Increase thread join timeout to ensure clean thread termination - Add detailed comments explaining timing requirements for stuck detection - Update assertion to verify detection within maximum wait time
1 parent 1f8f928 commit 24ff045

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

‎tests/test_subagent_monitoring.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ def test_heartbeat_updates(self) -> None:
102102

103103
def test_stuck_detection(self) -> None:
104104
"""Test stuck subagent detection."""
105-
# Use very short timeouts for testing
105+
# Use very short timeouts for testing, but give enough time for CI runners
106+
# The monitor needs: heartbeat_timeout to pass + (check_interval * max_stuck_checks)
107+
# With heartbeat_timeout=0.05, check_interval=0.02, max_stuck_checks=2
108+
# We need at least 0.05 + 0.02*2 = 0.09s minimum, but CI runners can be slow
106109
config = StuckDetectionConfig(
107110
stuck_timeout=0.1,
108111
heartbeat_timeout=0.05,
109112
check_interval=0.02,
110113
max_stuck_checks=2,
111-
thread_join_timeout=0.01, # Quick thread join timeout
114+
thread_join_timeout=0.1, # Give thread time to join cleanly
112115
)
113116
monitor = SubagentMonitor(config)
114117

@@ -119,12 +122,25 @@ def test_stuck_detection(self) -> None:
119122

120123
monitor.start_monitoring([subagent])
121124

122-
# Wait long enough for subagent to be considered stuck (reduced from 1.5s)
123-
time.sleep(0.2)
125+
# Poll with retries instead of fixed sleep to handle CI timing variance
126+
# We need to wait for stuck detection which requires:
127+
# 1. heartbeat_timeout (0.05s) to elapse
128+
# 2. Two check cycles (0.02s each) with stuck detection
129+
max_wait = 2.0 # Maximum time to wait (generous for slow CI)
130+
poll_interval = 0.05
131+
waited = 0.0
132+
detected = False
133+
134+
while waited < max_wait:
135+
time.sleep(poll_interval)
136+
waited += poll_interval
137+
stats = monitor.get_statistics()
138+
if stats["stuck_detected"] > 0:
139+
detected = True
140+
break
124141

125142
# Check that the monitor detected and handled the stuck subagent
126-
stats = monitor.get_statistics()
127-
assert stats["stuck_detected"] > 0
143+
assert detected, f"Stuck detection not triggered after {waited}s"
128144

129145
# Check that the subagent's status was updated
130146
tracker = monitor.progress_trackers["stuck_sub"]

0 commit comments

Comments
 (0)