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

add support for lifespan tasks #3312

Merged
merged 13 commits into from
May 22, 2024
Merged
Prev Previous commit
Next Next commit
test_lifespan: use polling to make the test more robust
Fix CI failure
  • Loading branch information
masenf committed May 17, 2024
commit ee89548b7778bbed1e2e47e3cc309cd882b665ab
10 changes: 5 additions & 5 deletions integration/test_lifespan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test cases for the FastAPI lifespan integration."""
import asyncio
from typing import Generator

import pytest
@@ -38,8 +37,8 @@ async def lifespan_task(inc: int = 1):
while True:
lifespan_task_global += inc # pyright: ignore[reportUnboundVariable]
await asyncio.sleep(0.1)
except asyncio.CancelledError:
print("Lifespan global cancelled.")
except asyncio.CancelledError as ce:
print(f"Lifespan global cancelled: {ce}.")
lifespan_task_global = 0

class LifespanState(rx.State):
@@ -104,8 +103,9 @@ async def test_lifespan(lifespan_app: AppHarness):
assert context_global.text == "2"
assert lifespan_app.app_module.lifespan_context_global == 2 # type: ignore

original_task_global_value = int(task_global.text)
await asyncio.sleep(0.3)
original_task_global_text = task_global.text
original_task_global_value = int(original_task_global_text)
lifespan_app.poll_for_content(task_global, exp_not_equal=original_task_global_text)
assert lifespan_app.app_module.lifespan_task_global > original_task_global_value # type: ignore
assert int(task_global.text) > original_task_global_value

Loading
Oops, something went wrong.