Show More
@@ -11,6 +11,9 b' import nose' | |||||
11 |
|
11 | |||
12 | from IPython.utils.tempdir import TemporaryDirectory |
|
12 | from IPython.utils.tempdir import TemporaryDirectory | |
13 |
|
13 | |||
|
14 | MAX_WAITTIME = 30 # seconds to wait for notebook server to start | |||
|
15 | POLL_INTERVAL = 0.1 # time between attempts | |||
|
16 | ||||
14 | class NotebookTestBase(TestCase): |
|
17 | class NotebookTestBase(TestCase): | |
15 | """A base class for tests that need a running notebook. |
|
18 | """A base class for tests that need a running notebook. | |
16 |
|
19 | |||
@@ -24,14 +27,14 b' class NotebookTestBase(TestCase):' | |||||
24 | def wait_until_alive(cls): |
|
27 | def wait_until_alive(cls): | |
25 | """Wait for the server to be alive""" |
|
28 | """Wait for the server to be alive""" | |
26 | url = 'http://localhost:%i/api/notebooks' % cls.port |
|
29 | url = 'http://localhost:%i/api/notebooks' % cls.port | |
27 | for _ in range(300): |
|
30 | for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): | |
28 | try: |
|
31 | try: | |
29 | requests.get(url) |
|
32 | requests.get(url) | |
30 | except requests.exceptions.ConnectionError: |
|
33 | except requests.exceptions.ConnectionError: | |
31 | if cls.notebook.poll() is not None: |
|
34 | if cls.notebook.poll() is not None: | |
32 | raise RuntimeError("The notebook server exited with status %s" \ |
|
35 | raise RuntimeError("The notebook server exited with status %s" \ | |
33 | % cls.notebook.poll()) |
|
36 | % cls.notebook.poll()) | |
34 |
time.sleep( |
|
37 | time.sleep(POLL_INTERVAL) | |
35 | else: |
|
38 | else: | |
36 | return |
|
39 | return | |
37 |
|
40 | |||
@@ -40,10 +43,10 b' class NotebookTestBase(TestCase):' | |||||
40 | @classmethod |
|
43 | @classmethod | |
41 | def wait_until_dead(cls): |
|
44 | def wait_until_dead(cls): | |
42 | """Wait for the server process to terminate after shutdown""" |
|
45 | """Wait for the server process to terminate after shutdown""" | |
43 | for _ in range(300): |
|
46 | for _ in range(int(MAX_WAITTIME/POLL_INTERVAL)): | |
44 | if cls.notebook.poll() is not None: |
|
47 | if cls.notebook.poll() is not None: | |
45 | return |
|
48 | return | |
46 |
time.sleep( |
|
49 | time.sleep(POLL_INTERVAL) | |
47 |
|
50 | |||
48 | raise TimeoutError("Undead notebook server") |
|
51 | raise TimeoutError("Undead notebook server") | |
49 |
|
52 | |||
@@ -55,7 +58,7 b' class NotebookTestBase(TestCase):' | |||||
55 | sys.executable, '-c', |
|
58 | sys.executable, '-c', | |
56 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', |
|
59 | 'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()', | |
57 | '--port=%d' % cls.port, |
|
60 | '--port=%d' % cls.port, | |
58 | '--port-retries=0', |
|
61 | '--port-retries=0', # Don't try any other ports | |
59 | '--no-browser', |
|
62 | '--no-browser', | |
60 | '--ipython-dir=%s' % cls.ipython_dir.name, |
|
63 | '--ipython-dir=%s' % cls.ipython_dir.name, | |
61 | '--notebook-dir=%s' % cls.notebook_dir.name, |
|
64 | '--notebook-dir=%s' % cls.notebook_dir.name, |
General Comments 0
You need to be logged in to leave comments.
Login now