diff --git a/tests/integration/test_background_task.py b/tests/integration/test_background_task.py index d7fe20824..2cf4d6a30 100644 --- a/tests/integration/test_background_task.py +++ b/tests/integration/test_background_task.py @@ -42,6 +42,11 @@ def BackgroundTask(): yield State.increment() # type: ignore await asyncio.sleep(0.005) + @rx.event(background=True) + async def fast_yielding(self): + for _ in range(100): + yield State.increment() + @rx.event def increment(self): self.counter += 1 @@ -375,3 +380,28 @@ def test_yield_in_async_with_self( yield_in_async_with_self_button.click() assert background_task._poll_for(lambda: counter.text == "2", timeout=5) + + +def test_fast_yielding( + background_task: AppHarness, + driver: WebDriver, + token: str, +) -> None: + """Test that fast yielding works as expected. + + Args: + background_task: harness for BackgroundTask app. + driver: WebDriver instance. + token: The token for the connected client. + """ + assert background_task.app_instance is not None + + # get a reference to all buttons + fast_yielding_button = driver.find_element(By.ID, "yield-increment") + + # get a reference to the counter + counter = driver.find_element(By.ID, "counter") + assert background_task._poll_for(lambda: counter.text == "0", timeout=5) + + fast_yielding_button.click() + assert background_task._poll_for(lambda: counter.text == "100", timeout=5)