Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC Valkey glide #4428

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
test fast yielding in background task
  • Loading branch information
benedikt-bartscher committed Nov 24, 2024
commit bc8720d31b8aa5fb285ebf2e8e0ddb598d608b38
30 changes: 30 additions & 0 deletions tests/integration/test_background_task.py
Original file line number Diff line number Diff line change
@@ -42,6 +42,11 @@ async def handle_event_yield_only(self):
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)