forked from tornadoweb/tornado
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow TCPServer.handle_stream to be a coroutine
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import socket | ||
|
||
from tornado import gen | ||
from tornado.iostream import IOStream | ||
from tornado.log import app_log | ||
from tornado.stack_context import NullContext | ||
from tornado.tcpserver import TCPServer | ||
from tornado.testing import AsyncTestCase, ExpectLog, bind_unused_port, gen_test | ||
|
||
|
||
class TCPServerTest(AsyncTestCase): | ||
@gen_test | ||
def test_handle_stream_coroutine_logging(self): | ||
# handle_stream may be a coroutine and any exception in its | ||
# Future will be logged. | ||
class TestServer(TCPServer): | ||
@gen.coroutine | ||
def handle_stream(self, stream, address): | ||
yield gen.moment | ||
stream.close() | ||
1/0 | ||
|
||
server = client = None | ||
try: | ||
sock, port = bind_unused_port() | ||
with NullContext(): | ||
server = TestServer() | ||
server.add_socket(sock) | ||
client = IOStream(socket.socket()) | ||
with ExpectLog(app_log, "Exception in callback"): | ||
yield client.connect(('localhost', port)) | ||
yield client.read_until_close() | ||
yield gen.moment | ||
finally: | ||
if server is not None: | ||
server.stop() | ||
if client is not None: | ||
client.close() |