Skip to content

Commit 8ca35fd

Browse files
authored
Merge pull request #4562 from youknowone/async-windows
double windows sleep for syntax_async until it success
2 parents d87921c + ae3de43 commit 8ca35fd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

extra_tests/snippets/syntax_async.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ async def __anext__(self):
3232
raise StopAsyncIteration
3333
return value
3434

35-
36-
if sys.platform.startswith("win"):
37-
SLEEP_UNIT = 0.5
38-
else:
39-
SLEEP_UNIT = 0.1
35+
SLEEP_UNIT = 0.1
4036

4137
async def a(s, m):
4238
async with ContextManager() as b:
@@ -48,19 +44,14 @@ async def a(s, m):
4844
await asyncio.sleep(SLEEP_UNIT)
4945

5046

51-
52-
async def main():
47+
async def run():
5348
tasks = [
5449
asyncio.create_task(c)
5550
for c in [a(SLEEP_UNIT * 0, "hello1"), a(SLEEP_UNIT * 1, "hello2"), a(SLEEP_UNIT * 2, "hello3"), a(SLEEP_UNIT * 3, "hello4")]
5651
]
5752
await asyncio.wait(tasks)
5853

59-
60-
ls = []
61-
asyncio.run(main(), debug=True)
62-
63-
assert ls == [
54+
expected = [
6455
1,
6556
3,
6657
1,
@@ -78,6 +69,24 @@ async def main():
7869
"hello3",
7970
"hello4",
8071
]
72+
ls = []
73+
74+
def test():
75+
global SLEEP_UNIT
76+
if sys.platform.startswith("win"):
77+
SLEEP_UNIT *= 2
78+
ls.clear()
79+
asyncio.run(run(), debug=True)
80+
assert ls == expected
81+
82+
83+
for i in reversed(range(10)):
84+
try:
85+
test()
86+
break
87+
except AssertionError:
88+
if i == 0:
89+
raise
8190

8291

8392
if sys.version_info < (3, 11, 0):

0 commit comments

Comments
 (0)