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)
| 1889 | |
| 1890 | @pytest.mark.asyncio |
| 1891 | async 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 |
nothing calls this directly
no test coverage detected