##// END OF EJS Templates
include stream creation in notebook KM tests
MinRK -
Show More
@@ -1,70 +1,76 b''
1 """Tests for the notebook kernel and session manager."""
1 """Tests for the notebook kernel and session manager."""
2
2
3 from subprocess import PIPE
3 from subprocess import PIPE
4 import time
4 import time
5 from unittest import TestCase
5 from unittest import TestCase
6
6
7 from IPython.config.loader import Config
7 from IPython.config.loader import Config
8 from IPython.frontend.html.notebook.kernelmanager import MultiKernelManager
8 from IPython.frontend.html.notebook.kernelmanager import MultiKernelManager
9 from IPython.zmq.kernelmanager import KernelManager
9 from IPython.zmq.kernelmanager import KernelManager
10
10
11 class TestKernelManager(TestCase):
11 class TestKernelManager(TestCase):
12
12
13 def _get_tcp_km(self):
13 def _get_tcp_km(self):
14 return MultiKernelManager()
14 return MultiKernelManager()
15
15
16 def _get_ipc_km(self):
16 def _get_ipc_km(self):
17 c = Config()
17 c = Config()
18 c.KernelManager.transport = 'ipc'
18 c.KernelManager.transport = 'ipc'
19 c.KernelManager.ip = 'test'
19 c.KernelManager.ip = 'test'
20 km = MultiKernelManager(config=c)
20 km = MultiKernelManager(config=c)
21 return km
21 return km
22
22
23 def _run_lifecycle(self, km):
23 def _run_lifecycle(self, km):
24 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
24 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
25 self.assertTrue(kid in km)
25 self.assertTrue(kid in km)
26 self.assertTrue(kid in km.list_kernel_ids())
26 self.assertTrue(kid in km.list_kernel_ids())
27 self.assertEqual(len(km),1)
27 self.assertEqual(len(km),1)
28 km.restart_kernel(kid)
28 km.restart_kernel(kid)
29 self.assertTrue(kid in km.list_kernel_ids())
29 self.assertTrue(kid in km.list_kernel_ids())
30 # We need a delay here to give the restarting kernel a chance to
30 # We need a delay here to give the restarting kernel a chance to
31 # restart. Otherwise, the interrupt will kill it, causing the test
31 # restart. Otherwise, the interrupt will kill it, causing the test
32 # suite to hang. The reason it *hangs* is that the shutdown
32 # suite to hang. The reason it *hangs* is that the shutdown
33 # message for the restart sometimes hasn't been sent to the kernel.
33 # message for the restart sometimes hasn't been sent to the kernel.
34 # Because linger is oo on the shell channel, the context can't
34 # Because linger is oo on the shell channel, the context can't
35 # close until the message is sent to the kernel, which is not dead.
35 # close until the message is sent to the kernel, which is not dead.
36 time.sleep(1.0)
36 time.sleep(1.0)
37 km.interrupt_kernel(kid)
37 km.interrupt_kernel(kid)
38 k = km.get_kernel(kid)
38 k = km.get_kernel(kid)
39 self.assertTrue(isinstance(k, KernelManager))
39 self.assertTrue(isinstance(k, KernelManager))
40 km.shutdown_kernel(kid)
40 km.shutdown_kernel(kid)
41 self.assertTrue(not kid in km)
41 self.assertTrue(not kid in km)
42
42
43 def _run_cinfo(self, km, transport, ip):
43 def _run_cinfo(self, km, transport, ip):
44 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
44 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
45 k = km.get_kernel(kid)
45 k = km.get_kernel(kid)
46 cinfo = km.get_connection_info(kid)
46 cinfo = km.get_connection_info(kid)
47 self.assertEqual(transport, cinfo['transport'])
47 self.assertEqual(transport, cinfo['transport'])
48 self.assertEqual(ip, cinfo['ip'])
48 self.assertEqual(ip, cinfo['ip'])
49 self.assertTrue('stdin_port' in cinfo)
49 self.assertTrue('stdin_port' in cinfo)
50 self.assertTrue('iopub_port' in cinfo)
50 self.assertTrue('iopub_port' in cinfo)
51 stream = km.create_iopub_stream(kid)
52 stream.close()
51 self.assertTrue('shell_port' in cinfo)
53 self.assertTrue('shell_port' in cinfo)
54 stream = km.create_shell_stream(kid)
55 stream.close()
52 self.assertTrue('hb_port' in cinfo)
56 self.assertTrue('hb_port' in cinfo)
57 stream = km.create_hb_stream(kid)
58 stream.close()
53 km.shutdown_kernel(kid)
59 km.shutdown_kernel(kid)
54
60
55 def test_tcp_lifecycle(self):
61 def test_tcp_lifecycle(self):
56 km = self._get_tcp_km()
62 km = self._get_tcp_km()
57 self._run_lifecycle(km)
63 self._run_lifecycle(km)
58
64
59 def test_tcp_cinfo(self):
65 def test_tcp_cinfo(self):
60 km = self._get_tcp_km()
66 km = self._get_tcp_km()
61 self._run_cinfo(km, 'tcp', '127.0.0.1')
67 self._run_cinfo(km, 'tcp', '127.0.0.1')
62
68
63 def test_ipc_lifecycle(self):
69 def test_ipc_lifecycle(self):
64 km = self._get_ipc_km()
70 km = self._get_ipc_km()
65 self._run_lifecycle(km)
71 self._run_lifecycle(km)
66
72
67 def test_ipc_cinfo(self):
73 def test_ipc_cinfo(self):
68 km = self._get_ipc_km()
74 km = self._get_ipc_km()
69 self._run_cinfo(km, 'ipc', 'test')
75 self._run_cinfo(km, 'ipc', 'test')
70
76
General Comments 0
You need to be logged in to leave comments. Login now