test inconsistent state if Spawner.start fails

This commit is contained in:
Min RK
2015-02-06 15:42:50 -08:00
parent c82903b85e
commit b4980f1736
2 changed files with 22 additions and 1 deletions

View File

@@ -322,9 +322,9 @@ class User(Base):
spawner.api_token = api_token spawner.api_token = api_token
self.spawn_pending = True self.spawn_pending = True
f = spawner.start()
# wait for spawner.start to return # wait for spawner.start to return
try: try:
f = spawner.start()
yield gen.with_timeout(timedelta(seconds=spawner.start_timeout), f) yield gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
except Exception as e: except Exception as e:
if isinstance(e, gen.TimeoutError): if isinstance(e, gen.TimeoutError):

View File

@@ -3,7 +3,11 @@
# Copyright (c) Jupyter Development Team. # Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import pytest
from tornado import gen
from .. import orm from .. import orm
from .mocking import MockSpawner
def test_server(db): def test_server(db):
@@ -82,3 +86,20 @@ def test_tokens(db):
assert found.match(token) assert found.match(token)
found = orm.APIToken.find(db, 'something else') found = orm.APIToken.find(db, 'something else')
assert found is None assert found is None
def test_spawn_fails(db, io_loop):
user = orm.User(name='aeofel')
db.add(user)
db.commit()
class BadSpawner(MockSpawner):
@gen.coroutine
def start(self):
raise RuntimeError("Split the party")
with pytest.raises(Exception) as exc:
io_loop.run_sync(lambda : user.spawn(BadSpawner))
assert user.server is None
assert not user.running