mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-21 04:10:17 +08:00
Don't wait forever for notebook server to launch/die for tests
Should turn occasional hangs into straightforward errors.
This commit is contained in:
parent
30df1c4546
commit
b0afd36408
@ -24,19 +24,24 @@ class NotebookTestBase(TestCase):
|
|||||||
def wait_until_alive(cls):
|
def wait_until_alive(cls):
|
||||||
"""Wait for the server to be alive"""
|
"""Wait for the server to be alive"""
|
||||||
url = 'http://localhost:%i/api/notebooks' % cls.port
|
url = 'http://localhost:%i/api/notebooks' % cls.port
|
||||||
while True:
|
for _ in range(300):
|
||||||
try:
|
try:
|
||||||
requests.get(url)
|
requests.get(url)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
|
if cls.notebook.poll() is not None:
|
||||||
|
raise RuntimeError("The notebook server exited with status %s" \
|
||||||
|
% cls.notebook.poll())
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
else:
|
else:
|
||||||
break
|
return
|
||||||
|
|
||||||
|
raise TimeoutError("The notebook server didn't start up correctly.")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def wait_until_dead(cls):
|
def wait_until_dead(cls):
|
||||||
"""Wait for the server to stop getting requests after shutdown"""
|
"""Wait for the server to stop getting requests after shutdown"""
|
||||||
url = 'http://localhost:%i/api/notebooks' % cls.port
|
url = 'http://localhost:%i/api/notebooks' % cls.port
|
||||||
while True:
|
for _ in range(300):
|
||||||
try:
|
try:
|
||||||
requests.get(url)
|
requests.get(url)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
@ -44,6 +49,8 @@ class NotebookTestBase(TestCase):
|
|||||||
else:
|
else:
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
|
|
||||||
|
raise TimeoutError("Undead notebook server")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_class(cls):
|
def setup_class(cls):
|
||||||
cls.ipython_dir = TemporaryDirectory()
|
cls.ipython_dir = TemporaryDirectory()
|
||||||
@ -52,6 +59,7 @@ class NotebookTestBase(TestCase):
|
|||||||
sys.executable, '-c',
|
sys.executable, '-c',
|
||||||
'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
|
'from IPython.html.notebookapp import launch_new_instance; launch_new_instance()',
|
||||||
'--port=%d' % cls.port,
|
'--port=%d' % cls.port,
|
||||||
|
'--port-retries=0',
|
||||||
'--no-browser',
|
'--no-browser',
|
||||||
'--ipython-dir=%s' % cls.ipython_dir.name,
|
'--ipython-dir=%s' % cls.ipython_dir.name,
|
||||||
'--notebook-dir=%s' % cls.notebook_dir.name,
|
'--notebook-dir=%s' % cls.notebook_dir.name,
|
||||||
|
Loading…
Reference in New Issue
Block a user