|
1 | 1 | """Tests for the notebook kernel and session manager."""
|
2 | 2 |
|
3 |
| -from subprocess import PIPE |
| 3 | +import os |
4 | 4 | import time
|
5 |
| -from unittest import TestCase |
| 5 | +import threading |
| 6 | +import multiprocessing as mp |
6 | 7 |
|
| 8 | +from subprocess import PIPE |
| 9 | +from unittest import TestCase |
7 | 10 | from traitlets.config.loader import Config
|
8 |
| -from ..localinterfaces import localhost |
9 | 11 | from jupyter_client import KernelManager
|
10 | 12 | from jupyter_client.multikernelmanager import MultiKernelManager
|
| 13 | + |
11 | 14 | from .utils import skip_win32
|
| 15 | +from ..localinterfaces import localhost |
| 16 | + |
| 17 | +TIMEOUT = 30 |
| 18 | + |
12 | 19 |
|
13 | 20 | class TestKernelManager(TestCase):
|
14 | 21 |
|
@@ -83,3 +90,43 @@ def test_ipc_lifecycle(self):
|
83 | 90 | def test_ipc_cinfo(self):
|
84 | 91 | km = self._get_ipc_km()
|
85 | 92 | self._run_cinfo(km, 'ipc', 'test')
|
| 93 | + |
| 94 | + def test_start_sequence_tcp_kernels(self): |
| 95 | + """Ensure that a sequence of kernel startups doesn't break anything.""" |
| 96 | + self._run_lifecycle(self._get_tcp_km()) |
| 97 | + self._run_lifecycle(self._get_tcp_km()) |
| 98 | + self._run_lifecycle(self._get_tcp_km()) |
| 99 | + |
| 100 | + |
| 101 | + def test_start_sequence_tcp_kernels(self): |
| 102 | + """Ensure that a sequence of kernel startups doesn't break anything.""" |
| 103 | + self._run_lifecycle(self._get_ipc_km()) |
| 104 | + self._run_lifecycle(self._get_ipc_km()) |
| 105 | + self._run_lifecycle(self._get_ipc_km()) |
| 106 | + |
| 107 | + def test_start_parallel_thread_kernels(self): |
| 108 | + self.test_tcp_lifecycle() |
| 109 | + |
| 110 | + thread = threading.Thread(target=self.test_tcp_lifecycle) |
| 111 | + thread2 = threading.Thread(target=self.test_tcp_lifecycle) |
| 112 | + try: |
| 113 | + thread.start() |
| 114 | + thread2.start() |
| 115 | + finally: |
| 116 | + thread.join() |
| 117 | + thread2.join() |
| 118 | + |
| 119 | + def test_start_parallel_process_kernels(self): |
| 120 | + self.test_tcp_lifecycle() |
| 121 | + |
| 122 | + thread = threading.Thread(target=self.test_tcp_lifecycle) |
| 123 | + proc = mp.Process(target=self.test_tcp_lifecycle) |
| 124 | + |
| 125 | + try: |
| 126 | + thread.start() |
| 127 | + proc.start() |
| 128 | + finally: |
| 129 | + thread.join() |
| 130 | + proc.join() |
| 131 | + |
| 132 | + assert proc.exitcode == 0 |
0 commit comments