Skip to content

Commit 05a2959

Browse files
author
Quentin Peter
committed
Merge branch 'repeat_tests' into _wait_input_request_reply
2 parents b2bd633 + f8befb1 commit 05a2959

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

ipykernel/kernelbase.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ def should_handle(self, stream, msg, idents):
225225
@gen.coroutine
226226
def dispatch_shell(self, stream, msg):
227227
"""dispatch shell requests"""
228-
# flush control requests first
229-
if self.control_stream:
230-
self.control_stream.flush()
231-
232228
idents, msg = self.session.feed_identities(msg, copy=False)
233229
try:
234230
msg = self.session.deserialize(msg, content=True, copy=False)
@@ -373,6 +369,9 @@ def dispatch_queue(self):
373369
"""
374370

375371
while True:
372+
# ensure control stream is flushed before processing shell messages
373+
if self.control_stream:
374+
self.control_stream.flush()
376375
# receive the next message and handle it
377376
try:
378377
yield self.process_one()

ipykernel/tests/test_embed_kernel.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from contextlib import contextmanager
1111
from subprocess import Popen, PIPE
12+
from flaky import flaky
1213

1314
from jupyter_client import BlockingKernelClient
1415
from jupyter_core import paths
@@ -29,38 +30,41 @@ def setup_kernel(cmd):
2930
kernel_manager: connected KernelManager instance
3031
"""
3132
kernel = Popen([sys.executable, '-c', cmd], stdout=PIPE, stderr=PIPE)
32-
connection_file = os.path.join(
33-
paths.jupyter_runtime_dir(),
34-
'kernel-%i.json' % kernel.pid,
35-
)
36-
# wait for connection file to exist, timeout after 5s
37-
tic = time.time()
38-
while not os.path.exists(connection_file) \
39-
and kernel.poll() is None \
40-
and time.time() < tic + SETUP_TIMEOUT:
41-
time.sleep(0.1)
42-
43-
if kernel.poll() is not None:
44-
o,e = kernel.communicate()
45-
e = py3compat.cast_unicode(e)
46-
raise IOError("Kernel failed to start:\n%s" % e)
47-
48-
if not os.path.exists(connection_file):
49-
if kernel.poll() is None:
50-
kernel.terminate()
51-
raise IOError("Connection file %r never arrived" % connection_file)
52-
53-
client = BlockingKernelClient(connection_file=connection_file)
54-
client.load_connection_file()
55-
client.start_channels()
56-
client.wait_for_ready()
57-
5833
try:
59-
yield client
34+
connection_file = os.path.join(
35+
paths.jupyter_runtime_dir(),
36+
'kernel-%i.json' % kernel.pid,
37+
)
38+
# wait for connection file to exist, timeout after 5s
39+
tic = time.time()
40+
while not os.path.exists(connection_file) \
41+
and kernel.poll() is None \
42+
and time.time() < tic + SETUP_TIMEOUT:
43+
time.sleep(0.1)
44+
45+
if kernel.poll() is not None:
46+
o,e = kernel.communicate()
47+
e = py3compat.cast_unicode(e)
48+
raise IOError("Kernel failed to start:\n%s" % e)
49+
50+
if not os.path.exists(connection_file):
51+
if kernel.poll() is None:
52+
kernel.terminate()
53+
raise IOError("Connection file %r never arrived" % connection_file)
54+
55+
client = BlockingKernelClient(connection_file=connection_file)
56+
client.load_connection_file()
57+
client.start_channels()
58+
client.wait_for_ready()
59+
try:
60+
yield client
61+
finally:
62+
client.stop_channels()
6063
finally:
61-
client.stop_channels()
6264
kernel.terminate()
6365

66+
67+
@flaky(max_runs=3)
6468
def test_embed_kernel_basic():
6569
"""IPython.embed_kernel() is basically functional"""
6670
cmd = '\n'.join([
@@ -93,6 +97,8 @@ def test_embed_kernel_basic():
9397
text = content['data']['text/plain']
9498
assert '10' in text
9599

100+
101+
@flaky(max_runs=3)
96102
def test_embed_kernel_namespace():
97103
"""IPython.embed_kernel() inherits calling namespace"""
98104
cmd = '\n'.join([
@@ -128,6 +134,7 @@ def test_embed_kernel_namespace():
128134
content = msg['content']
129135
assert not content['found']
130136

137+
@flaky(max_runs=3)
131138
def test_embed_kernel_reentrant():
132139
"""IPython.embed_kernel() can be called multiple times"""
133140
cmd = '\n'.join([

ipykernel/tests/test_kernel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212

1313
import nose.tools as nt
14+
from flaky import flaky
1415

1516
from IPython.testing import decorators as dec, tools as tt
1617
from ipython_genutils import py3compat
@@ -75,6 +76,7 @@ def test_sys_path_profile_dir():
7576
assert '' in sys_path
7677

7778

79+
@flaky(max_runs=3)
7880
@dec.skipif(sys.platform == 'win32', "subprocess prints fail on Windows")
7981
def test_subprocess_print():
8082
"""printing from forked mp.Process"""
@@ -104,6 +106,7 @@ def test_subprocess_print():
104106
_check_master(kc, expected=True, stream="stderr")
105107

106108

109+
@flaky(max_runs=3)
107110
def test_subprocess_noprint():
108111
"""mp.Process without print doesn't trigger iostream mp_mode"""
109112
with kernel() as kc:
@@ -126,6 +129,7 @@ def test_subprocess_noprint():
126129
_check_master(kc, expected=True, stream="stderr")
127130

128131

132+
@flaky(max_runs=3)
129133
@dec.skipif(sys.platform == 'win32', "subprocess prints fail on Windows")
130134
def test_subprocess_error():
131135
"""error in mp.Process doesn't crash"""

ipykernel/tests/test_start_kernel.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from .test_embed_kernel import setup_kernel
2+
from flaky import flaky
23

34
TIMEOUT = 15
45

6+
7+
@flaky(max_runs=3)
58
def test_ipython_start_kernel_userns():
69
cmd = ('from IPython import start_kernel\n'
710
'ns = {"tre": 123}\n'
@@ -27,6 +30,8 @@ def test_ipython_start_kernel_userns():
2730
text = content['data']['text/plain']
2831
assert u'DummyMod' in text
2932

33+
34+
@flaky(max_runs=3)
3035
def test_ipython_start_kernel_no_userns():
3136
# Issue #4188 - user_ns should be passed to shell as None, not {}
3237
cmd = ('from IPython import start_kernel\n'

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def run(self):
9797
'test': [
9898
'pytest',
9999
'pytest-cov',
100+
'flaky',
100101
'nose', # nose because there are still a few nose.tools imports hanging around
101102
],
102103
},

0 commit comments

Comments
 (0)