Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions tests/units/utils/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import asyncio
import contextlib
import os
from unittest.mock import Mock

import pytest

from reflex.utils.tasks import ensure_task

CI = bool(os.environ.get("CI", False))


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


async def test_ensure_task_limit_window_passed():
"""Test that ensure_task raises after exceeding exception limit within the limit window."""
"""Test that ensure_task resets exception limit past the limit window."""
call_count = 0

async def faulty_coro():
nonlocal call_count
call_count += 1
await asyncio.sleep(0.05)
await asyncio.sleep(0.5 if CI else 0.05)
if call_count > 3:
raise RuntimeError("Test Passed") # noqa: EM101
raise ValueError("Should have been suppressed") # noqa: EM101
Expand All @@ -90,8 +93,8 @@ async def faulty_coro():
coro_function=faulty_coro,
suppress_exceptions=[ValueError],
exception_delay=0,
exception_limit=3,
exception_limit_window=0.1,
exception_limit=2,
exception_limit_window=0.1 if CI else 0.01,
)

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