MCPcopy
hub / github.com/stanfordnlp/dspy / verify_asyncify

Function verify_asyncify

tests/utils/test_asyncify.py:34–48  ·  view source on GitHub ↗
(capacity: int, number_of_tasks: int, wait: float = 0.5)

Source from the content-addressed store, hash-verified

32 await asyncio.gather(*[ask_the_question(wait) for _ in range(n)])
33
34 async def verify_asyncify(capacity: int, number_of_tasks: int, wait: float = 0.5):
35 with dspy.context(async_max_workers=capacity):
36 start = time()
37 await run_n_tasks(number_of_tasks, wait)
38 end = time()
39 total_time = end - start
40
41 # If asyncify is working correctly, the total time should be less than the total number of loops
42 # `(number_of_tasks / capacity)` times wait time, plus the computational overhead. The lower bound should
43 # be `math.floor(number_of_tasks * 1.0 / capacity) * wait` because there are more than
44 # `math.floor(number_of_tasks * 1.0 / capacity)` loops.
45 lower_bound = math.floor(number_of_tasks * 1.0 / capacity) * wait
46 upper_bound = math.ceil(number_of_tasks * 1.0 / capacity) * wait + 2 * wait # 2*wait for buffer
47
48 assert lower_bound < total_time < upper_bound
49
50 await verify_asyncify(4, 10)
51 await verify_asyncify(8, 15)

Callers 1

test_asyncifyFunction · 0.85

Calls 2

run_n_tasksFunction · 0.85
contextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…