MCPcopy Create free account
hub / github.com/dot-agent/nextpy / test_background_task_reset

Function test_background_task_reset

tests/test_state.py:1891–1922  ·  view source on GitHub ↗

Test that a background task calling reset is protected by the state proxy. Args: mock_app: An app that will be returned by `get_app()` token: A token.

(mock_app: xt.App, token: str)

Source from the content-addressed store, hash-verified

1889
1890@pytest.mark.asyncio
1891async def test_background_task_reset(mock_app: xt.App, token: str):
1892 """Test that a background task calling reset is protected by the state proxy.
1893
1894 Args:
1895 mock_app: An app that will be returned by `get_app()`
1896 token: A token.
1897 """
1898 router_data = {"query": {}}
1899 mock_app.state_manager.state = mock_app.state = BackgroundTaskState
1900 async for update in xt.app.process( # type: ignore
1901 mock_app,
1902 Event(
1903 token=token,
1904 name=f"{BackgroundTaskState.get_name()}.background_task_reset",
1905 router_data=router_data,
1906 payload={},
1907 ),
1908 sid="",
1909 headers={},
1910 client_ip="",
1911 ):
1912 # background task returns empty update immediately
1913 assert update == StateUpdate()
1914
1915 # Explicit wait for background tasks
1916 for task in tuple(mock_app.background_tasks):
1917 await task
1918 assert not mock_app.background_tasks
1919
1920 assert (await mock_app.state_manager.get_state(token)).order == [
1921 "reset",
1922 ]
1923
1924
1925@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 4

EventClass · 0.90
StateUpdateClass · 0.90
get_nameMethod · 0.45
get_stateMethod · 0.45

Tested by

no test coverage detected