Skip to content

Commit 3c564ab

Browse files
authored
Flaky test test_ensure_task_limit_window_passed (#5959)
* Flaky test test_ensure_task_limit_window_passed Try to make the test less flaky by making the iteration wait time equal to the exception_limit_window and reducing the exception_limit from 3 to 2. This should still catch the case in question, but be less timing dependent. * Use longer delay in CI to make race harder to hit
1 parent d52e6ed commit 3c564ab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/units/utils/test_tasks.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import asyncio
22
import contextlib
3+
import os
34
from unittest.mock import Mock
45

56
import pytest
67

78
from reflex.utils.tasks import ensure_task
89

10+
CI = bool(os.environ.get("CI", False))
11+
912

1013
class NotSuppressedError(Exception):
1114
"""An exception that should not be suppressed."""
@@ -72,13 +75,13 @@ async def faulty_coro(): # noqa: RUF029
7275

7376

7477
async def test_ensure_task_limit_window_passed():
75-
"""Test that ensure_task raises after exceeding exception limit within the limit window."""
78+
"""Test that ensure_task resets exception limit past the limit window."""
7679
call_count = 0
7780

7881
async def faulty_coro():
7982
nonlocal call_count
8083
call_count += 1
81-
await asyncio.sleep(0.05)
84+
await asyncio.sleep(0.5 if CI else 0.05)
8285
if call_count > 3:
8386
raise RuntimeError("Test Passed") # noqa: EM101
8487
raise ValueError("Should have been suppressed") # noqa: EM101
@@ -90,8 +93,8 @@ async def faulty_coro():
9093
coro_function=faulty_coro,
9194
suppress_exceptions=[ValueError],
9295
exception_delay=0,
93-
exception_limit=3,
94-
exception_limit_window=0.1,
96+
exception_limit=2,
97+
exception_limit_window=0.1 if CI else 0.01,
9598
)
9699

97100
with contextlib.suppress(asyncio.CancelledError), pytest.raises(RuntimeError):

0 commit comments

Comments
 (0)