Skip to content

Commit 5f169bc

Browse files
authored
test_lifespan: stop periodic events (#4600)
avoid lingering events after getting the information we came for
1 parent 08d9fbf commit 5f169bc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/integration/test_lifespan.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ async def lifespan_task(inc: int = 1):
4343
lifespan_task_global = 0
4444

4545
class LifespanState(rx.State):
46+
interval: int = 100
47+
4648
@rx.var
4749
def task_global(self) -> int:
4850
return lifespan_task_global
@@ -59,7 +61,15 @@ def index():
5961
return rx.vstack(
6062
rx.text(LifespanState.task_global, id="task_global"),
6163
rx.text(LifespanState.context_global, id="context_global"),
62-
rx.moment(interval=100, on_change=LifespanState.tick),
64+
rx.button(
65+
rx.moment(
66+
interval=LifespanState.interval, on_change=LifespanState.tick
67+
),
68+
on_click=LifespanState.set_interval( # type: ignore
69+
rx.cond(LifespanState.interval, 0, 100)
70+
),
71+
id="toggle-tick",
72+
),
6373
)
6474

6575
app = rx.App()
@@ -108,6 +118,7 @@ async def test_lifespan(lifespan_app: AppHarness):
108118
original_task_global_text = task_global.text
109119
original_task_global_value = int(original_task_global_text)
110120
lifespan_app.poll_for_content(task_global, exp_not_equal=original_task_global_text)
121+
driver.find_element(By.ID, "toggle-tick").click() # avoid teardown errors
111122
assert lifespan_app.app_module.lifespan_task_global > original_task_global_value # type: ignore
112123
assert int(task_global.text) > original_task_global_value
113124

0 commit comments

Comments
 (0)