Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cortex/tests/test_webgl_serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cortex.webgl.serve as serve


def test_webapp_run_uses_current_ioloop(monkeypatch):
class FakeIOLoop:
def __init__(self):
self.started = False

def start(self):
self.started = True

class FakeHTTPServer:
def __init__(self, application, io_loop=None):
self.application = application
self.io_loop = io_loop
self.listen_port = None

def listen(self, port):
self.listen_port = port

fake_ioloop = FakeIOLoop()

monkeypatch.setattr(serve.tornado.ioloop.IOLoop, "current", lambda: fake_ioloop)
monkeypatch.setattr(serve.tornado.httpserver, "HTTPServer", FakeHTTPServer)

app = serve.WebApp([], 0)
app.run()

assert app.ioloop is fake_ioloop
assert fake_ioloop.started
assert app.server.listen_port == 0
6 changes: 1 addition & 5 deletions cortex/webgl/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,7 @@ def n_clients(self) -> int:
return num

def run(self):
ioloop: tornado.ioloop.IOLoop = (
tornado.ioloop.IOLoop()
) # why is annotation necessary?
ioloop.clear_current()
ioloop.make_current()
ioloop: tornado.ioloop.IOLoop = tornado.ioloop.IOLoop.current()
self.ioloop = ioloop
application = tornado.web.Application(self.handlers, gzip=True)
# If tornado version is 5.0 or greater, io_loop arg does not exist
Expand Down