test fast yielding in background task
This commit is contained in:
parent
697e26c25b
commit
bc8720d31b
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user