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

Function test_background_task_no_block

tests/test_state.py:1773–1887  ·  view source on GitHub ↗

Test that a background task does not block other events. 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

1771
1772@pytest.mark.asyncio
1773async def test_background_task_no_block(mock_app: xt.App, token: str):
1774 """Test that a background task does not block other events.
1775
1776 Args:
1777 mock_app: An app that will be returned by `get_app()`
1778 token: A token.
1779 """
1780 router_data = {"query": {}}
1781 mock_app.state_manager.state = mock_app.state = BackgroundTaskState
1782 async for update in xt.app.process( # type: ignore
1783 mock_app,
1784 Event(
1785 token=token,
1786 name=f"{BackgroundTaskState.get_name()}.background_task",
1787 router_data=router_data,
1788 payload={},
1789 ),
1790 sid="",
1791 headers={},
1792 client_ip="",
1793 ):
1794 # background task returns empty update immediately
1795 assert update == StateUpdate()
1796
1797 # wait for the coroutine to start
1798 await asyncio.sleep(0.5 if CI else 0.1)
1799 assert len(mock_app.background_tasks) == 1
1800
1801 # Process another normal event
1802 async for update in xt.app.process( # type: ignore
1803 mock_app,
1804 Event(
1805 token=token,
1806 name=f"{BackgroundTaskState.get_name()}.other",
1807 router_data=router_data,
1808 payload={},
1809 ),
1810 sid="",
1811 headers={},
1812 client_ip="",
1813 ):
1814 # other task returns delta
1815 assert update == StateUpdate(
1816 delta={
1817 BackgroundTaskState.get_name(): {
1818 "order": [
1819 "background_task:start",
1820 "other",
1821 ],
1822 "computed_order": [
1823 "background_task:start",
1824 "other",
1825 ],
1826 }
1827 }
1828 )
1829
1830 # Explicit wait for background tasks

Callers

nothing calls this directly

Calls 6

EventClass · 0.90
StateUpdateClass · 0.90
lenFunction · 0.85
get_nameMethod · 0.45
get_stateMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected