File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,18 +61,18 @@ def test_simple_print():
6161def test_async_cell_waiting_for_comm_reply ():
6262 with new_kernel () as kc :
6363 msg_id = kc .execute (
64- """import anyio , comm
65- reply = anyio.Future ()
64+ """import asyncio , comm
65+ reply = asyncio.get_running_loop().create_future ()
6666widget = comm.create_comm(target_name='comm-reply-test')
67- widget.on_msg(lambda msg: setattr(reply, 'return_value', msg['content']['data']['value']))
68- with anyio.fail_after(5):
69- await reply.wait()
70- result = reply.return_value
67+ widget.on_msg(lambda msg: reply.set_result(msg['content']['data']['value']))
68+ result = await asyncio.wait_for(reply, 5)
7169assert result == 42
7270"""
7371 )
7472 while True :
7573 msg = kc .get_iopub_msg (timeout = 10 )
74+ if msg ["msg_type" ] == "error" and msg ["parent_header" ].get ("msg_id" ) == msg_id :
75+ raise AssertionError ("\n " .join (msg ["content" ]["traceback" ]))
7676 if msg ["msg_type" ] == "comm_open" and msg ["parent_header" ].get ("msg_id" ) == msg_id :
7777 comm_id = msg ["content" ]["comm_id" ]
7878 break
Original file line number Diff line number Diff line change @@ -144,24 +144,27 @@ def test_comm_reply_follows_requesting_subshell():
144144
145145 msg = execute_request (
146146 kc ,
147- """import anyio , threading
148- reply = anyio.Future ()
147+ """import asyncio , threading
148+ reply = asyncio.get_running_loop().create_future ()
149149request_thread = threading.get_ident()
150150def on_reply(message):
151151 global callback_thread
152152 callback_thread = threading.get_ident()
153- reply.return_value = message['content']['data']['content']['value']
153+ reply.set_result( message['content']['data']['content']['value'])
154154widget.on_msg(on_reply)
155155widget.send({'method': 'custom', 'content': {'id': 'request-1', 'operation': 'get'}})
156- with anyio.fail_after(2):
157- await reply.wait()
158- assert reply.return_value == 42
156+ assert await asyncio.wait_for(reply, 2) == 42
159157assert callback_thread == request_thread
160158""" ,
161159 None ,
162160 )
163161 while True :
164162 outgoing = kc .get_iopub_msg (timeout = 10 )
163+ if (
164+ outgoing ["msg_type" ] == "error"
165+ and outgoing ["parent_header" ].get ("msg_id" ) == msg ["header" ]["msg_id" ]
166+ ):
167+ raise AssertionError ("\n " .join (outgoing ["content" ]["traceback" ]))
165168 if (
166169 outgoing ["msg_type" ] == "comm_msg"
167170 and outgoing ["parent_header" ].get ("msg_id" ) == msg ["header" ]["msg_id" ]
You can’t perform that action at this time.
0 commit comments