66
77import platform
88import time
9- from datetime import datetime , timedelta
109
1110import pytest
1211from jupyter_client .blocking .client import BlockingKernelClient
@@ -186,7 +185,9 @@ def test_run_concurrently_timing(include_main_shell):
186185 kc , "import threading as t, time; b=t.Barrier(2); print('ok')" , None
187186 )
188187
189- times = (0.2 , 0.2 )
188+ times = (0.4 ,) * 2
189+ min_duration = times [0 ]
190+ max_duration = sum (times )
190191 # Prepare messages, times are sleep times in seconds.
191192 # Identical times for both subshells is a harder test as preparing and sending
192193 # the execute_reply messages may overlap.
@@ -198,24 +199,27 @@ def test_run_concurrently_timing(include_main_shell):
198199 msgs .append (msg )
199200
200201 # Send messages
201- start = datetime . now ()
202+ start = time . monotonic ()
202203 for msg in msgs :
203204 kc .shell_channel .send (msg )
204205
205- _ = get_replies (kc , [msg ["msg_id" ] for msg in msgs ])
206- end = datetime .now ()
206+ replies = get_replies (kc , [msg ["msg_id" ] for msg in msgs ])
207+ end = time .monotonic ()
208+ for reply in replies :
209+ assert reply ["content" ]["status" ] == "ok"
207210
208211 for subshell_id in subshell_ids :
209212 if subshell_id :
210213 delete_subshell_helper (kc , subshell_id )
211214
212215 duration = end - start
213- assert duration >= timedelta ( seconds = max ( times ))
216+ assert duration >= min_duration
214217 # Care is needed with this test as runtime conditions such as gathering
215218 # coverage can slow it down causing the following assert to fail.
216219 # The sleep time of 0.2 is empirically determined to run OK in CI, but
217220 # consider increasing it if the following fails.
218- assert duration < timedelta (seconds = sum (times ))
221+
222+ assert duration < max_duration
219223
220224
221225@pytest .mark .xfail (strict = False , reason = "subshell still sometime give different results" )
0 commit comments