Skip to content

Commit 5515a4f

Browse files
committed
Add some sleeps to make more realistic
1 parent 930d9b7 commit 5515a4f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mypyc/test-data/run-async.test

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ async def make_list(a: list[int]) -> list[int]:
390390
async def spill() -> list[int]:
391391
a: list[int] = []
392392
for i in range(5):
393+
await asyncio.sleep(0.0001)
393394
a = (await make_list(a + [1])) + a + (await make_list(a + [2]))
394395
return a
395396

@@ -398,17 +399,22 @@ async def bar(n: int) -> None:
398399
await spill()
399400

400401
def test_spilled() -> None:
401-
assert_no_leaks(lambda: bar(100), 2)
402+
assert_no_leaks(lambda: bar(40), 2)
402403

403404
async def raise_deep(n: int) -> str:
404405
if n == 0:
406+
await asyncio.sleep(0.0001)
405407
raise TypeError(str(n))
406408
else:
409+
if n == 2:
410+
await asyncio.sleep(0.0001)
407411
return await raise_deep(n - 1)
408412

409413
async def maybe_raise(n: int) -> str:
410414
if n % 3 == 0:
411-
await raise_deep(10)
415+
await raise_deep(5)
416+
elif n % 29 == 0:
417+
await asyncio.sleep(0.0001)
412418
return str(n)
413419

414420
async def exc(n: int) -> list[str]:
@@ -421,7 +427,7 @@ async def exc(n: int) -> list[str]:
421427
return a
422428

423429
def test_exception() -> None:
424-
assert_no_leaks(lambda: exc(100), 2)
430+
assert_no_leaks(lambda: exc(50), 2)
425431

426432
class C:
427433
def __init__(self, s: str) -> None:
@@ -431,7 +437,9 @@ async def id(c: C) -> C:
431437
return c
432438

433439
async def stolen_helper(c: C, s: str) -> str:
440+
await asyncio.sleep(0.0001)
434441
(await id(c)).s = await concat_one(s)
442+
await asyncio.sleep(0.0001)
435443
return c.s
436444

437445
async def stolen(n: int) -> int:
@@ -442,7 +450,8 @@ async def stolen(n: int) -> int:
442450
return n
443451

444452
def test_stolen() -> None:
445-
assert_no_leaks(lambda: stolen(1000), 2)
453+
assert_no_leaks(lambda: stolen(100), 2)
446454

447455
[file asyncio/__init__.pyi]
448456
def run(x: object) -> object: ...
457+
async def sleep(t: float) -> None: ...

0 commit comments

Comments
 (0)