MCPcopy
hub / github.com/ray-project/ray / test_run_background_task

Function test_run_background_task

python/ray/_common/tests/test_utils.py:90–113  ·  view source on GitHub ↗

Test the run_background_task utility function.

()

Source from the content-addressed store, hash-verified

88
89@pytest.mark.asyncio
90async def test_run_background_task():
91 """Test the run_background_task utility function."""
92 result = {}
93
94 async def co():
95 result["start"] = 1
96 await asyncio.sleep(0)
97 result["end"] = 1
98
99 run_background_task(co())
100
101 # Background task is running.
102 assert len(_BACKGROUND_TASKS) == 1
103 # co executed.
104 await asyncio.sleep(0)
105 # await asyncio.sleep(0) from co is reached.
106 await asyncio.sleep(0)
107 # co finished and callback called.
108 await asyncio.sleep(0)
109 # The task should be removed from the set once it finishes.
110 assert len(_BACKGROUND_TASKS) == 0
111
112 assert result.get("start") == 1
113 assert result.get("end") == 1
114
115
116class TestTryToCreateDirectory:

Callers

nothing calls this directly

Calls 4

run_background_taskFunction · 0.90
coFunction · 0.70
getMethod · 0.65
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…