from tornado.concurrent import Future
from tornado.httpclient import HTTPError, HTTPRequest
-from tornado.log import gen_log
+from tornado.log import gen_log, app_log
from tornado.testing import AsyncHTTPTestCase, gen_test, bind_unused_port, ExpectLog
from tornado.test.util import unittest
from tornado.web import Application, RequestHandler
self.write_message(message, isinstance(message, bytes))
+class ErrorInOnMessageHandler(TestWebSocketHandler):
+ def on_message(self, message):
+ 1/0
+
+
class HeaderHandler(TestWebSocketHandler):
def open(self):
try:
('/header', HeaderHandler, dict(close_future=self.close_future)),
('/close_reason', CloseReasonHandler,
dict(close_future=self.close_future)),
+ ('/error_in_on_message', ErrorInOnMessageHandler,
+ dict(close_future=self.close_future)),
])
def test_http_request(self):
ws.close()
yield self.close_future
+ @gen_test
+ def test_error_in_on_message(self):
+ ws = yield websocket_connect(
+ 'ws://localhost:%d/error_in_on_message' % self.get_http_port())
+ ws.write_message('hello')
+ with ExpectLog(app_log, "Uncaught exception"):
+ response = yield ws.read_message()
+ self.assertIs(response, None)
+ ws.close()
+ yield self.close_future
+
@gen_test
def test_websocket_http_fail(self):
with self.assertRaises(HTTPError) as cm: