self.close(1001, "goodbye")
+class AsyncPrepareHandler(TestWebSocketHandler):
+ @gen.coroutine
+ def prepare(self):
+ yield gen.moment
+
+ def on_message(self, message):
+ self.write_message(message)
+
+
class WebSocketBaseTestCase(AsyncHTTPTestCase):
@gen.coroutine
def ws_connect(self, path, compression_options=None):
dict(close_future=self.close_future)),
('/error_in_on_message', ErrorInOnMessageHandler,
dict(close_future=self.close_future)),
+ ('/async_prepare', AsyncPrepareHandler,
+ dict(close_future=self.close_future)),
])
def test_http_request(self):
self.assertEqual(code, 1001)
self.assertEqual(reason, 'goodbye')
+ @gen_test
+ def test_async_prepare(self):
+ # Previously, an async prepare method triggered a bug that would
+ # result in a timeout on test shutdown (and a memory leak).
+ ws = yield self.ws_connect('/async_prepare')
+ ws.write_message('hello')
+ res = yield ws.read_message()
+ self.assertEqual(res, 'hello')
+
@gen_test
def test_check_origin_valid_no_path(self):
port = self.get_http_port()
def tearDown(self):
self.http_server.stop()
- self.io_loop.run_sync(self.http_server.close_all_connections)
+ self.io_loop.run_sync(self.http_server.close_all_connections,
+ timeout=get_async_test_timeout())
if (not IOLoop.initialized() or
self.http_client.io_loop is not IOLoop.instance()):
self.http_client.close()