Skip to content

Commit a019e90

Browse files
fix: flaky web test for connection monitor (#2395)
fix flaky web test for connection monitor
1 parent 576228d commit a019e90

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

web/src/components/common/tests/ConnectionMonitor.test.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ describe('ConnectionMonitor', () => {
7272
expect(screen.getByText('Cannot connect')).toBeInTheDocument();
7373
}, { timeout: 6000 });
7474

75-
// Should show countdown
75+
// Should show countdown - wait for it to appear since it's async
7676
await waitFor(() => {
7777
expect(screen.getByText(/Retrying in \d+ second/)).toBeInTheDocument();
78-
}, { timeout: 1000 });
78+
}, { timeout: 2000 });
7979

8080
// Modal should disappear when automatic retry succeeds
81+
// This should happen after the RETRY_INTERVAL (10 seconds)
8182
await waitFor(() => {
8283
expect(screen.queryByText('Cannot connect')).not.toBeInTheDocument();
8384
}, { timeout: 12000 });
@@ -92,10 +93,25 @@ describe('ConnectionMonitor', () => {
9293

9394
render(<ConnectionMonitor />);
9495

96+
// Wait for modal to appear
9597
await waitFor(() => {
9698
expect(screen.getByText('Cannot connect')).toBeInTheDocument();
9799
}, { timeout: 4000 });
98100

99-
expect(screen.getByText(/Retrying in \d+ second/)).toBeInTheDocument();
100-
}, 6000);
101+
await waitFor(() => {
102+
expect(screen.getByText(/Retrying in \d+ second/)).toBeInTheDocument();
103+
}, { timeout: 2000 });
104+
105+
// Verify the countdown is actually working by checking it's a reasonable value
106+
const countdownElement = screen.getByText(/Retrying in \d+ second/);
107+
const countdownText = countdownElement.textContent || '';
108+
const secondsMatch = countdownText.match(/Retrying in (\d+) second/);
109+
110+
if (secondsMatch) {
111+
const seconds = parseInt(secondsMatch[1], 10);
112+
// Should be between 1-10 seconds (since RETRY_INTERVAL is 10 seconds)
113+
expect(seconds).toBeGreaterThan(0);
114+
expect(seconds).toBeLessThanOrEqual(10);
115+
}
116+
}, 8000);
101117
});

0 commit comments

Comments
 (0)