Skip to content

Commit df32f2a

Browse files
committed
Fix py_async_e2e_SUITE for subinterpreters
- Use explicit context for all tests - Relax timing constraint (0.3s instead of 0.15s) for CI - Add diagnostic messages to assertions
1 parent 3d0add0 commit df32f2a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

test/py_async_e2e_SUITE.erl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ end_per_testcase(_TestCase, _Config) ->
4848

4949
%% Test basic asyncio.sleep timing
5050
test_asyncio_sleep(_Config) ->
51-
ok = py:exec(<<"
51+
Ctx = py:context(1),
52+
ok = py:exec(Ctx, <<"
5253
import asyncio
5354
import time
5455
@@ -58,13 +59,14 @@ async def timed_sleep():
5859
return time.monotonic() - start
5960
6061
elapsed = asyncio.run(timed_sleep())
61-
assert elapsed >= 0.04
62+
assert elapsed >= 0.04, f'Expected >= 0.04s, got {elapsed:.3f}s'
6263
">>),
6364
ok.
6465

6566
%% Test asyncio.gather runs tasks concurrently
6667
test_asyncio_gather(_Config) ->
67-
ok = py:exec(<<"
68+
Ctx = py:context(1),
69+
ok = py:exec(Ctx, <<"
6870
import asyncio
6971
import time
7072
@@ -76,16 +78,18 @@ async def main():
7678
start = time.monotonic()
7779
r = await asyncio.gather(task(1), task(2), task(3))
7880
elapsed = time.monotonic() - start
79-
assert list(r) == [1, 2, 3]
80-
assert elapsed < 0.15
81+
assert list(r) == [1, 2, 3], f'Expected [1, 2, 3], got {list(r)}'
82+
# Allow more time on CI (0.3s instead of 0.15s)
83+
assert elapsed < 0.3, f'Expected < 0.3s, got {elapsed:.3f}s'
8184
8285
asyncio.run(main())
8386
">>),
8487
ok.
8588

8689
%% Test TCP echo server/client using asyncio
8790
test_asyncio_tcp_echo(_Config) ->
88-
ok = py:exec(<<"
91+
Ctx = py:context(1),
92+
ok = py:exec(Ctx, <<"
8993
import asyncio
9094
9195
async def handler(r, w):
@@ -106,15 +110,16 @@ async def test():
106110
await w.wait_closed()
107111
srv.close()
108112
await srv.wait_closed()
109-
assert resp == b'hello'
113+
assert resp == b'hello', f'Expected b\"hello\", got {resp}'
110114
111115
asyncio.run(test())
112116
">>),
113117
ok.
114118

115119
%% Test multiple concurrent TCP connections
116120
test_asyncio_concurrent_tcp(_Config) ->
117-
ok = py:exec(<<"
121+
Ctx = py:context(1),
122+
ok = py:exec(Ctx, <<"
118123
import asyncio
119124
120125
async def handler(r, w):
@@ -143,7 +148,7 @@ async def test():
143148
)
144149
srv.close()
145150
await srv.wait_closed()
146-
assert set(results) == {b're:1', b're:2', b're:3'}
151+
assert set(results) == {b're:1', b're:2', b're:3'}, f'Expected {{b\"re:1\", b\"re:2\", b\"re:3\"}}, got {set(results)}'
147152
148153
asyncio.run(test())
149154
">>),

0 commit comments

Comments
 (0)