From: Ben Darnell Date: Sun, 8 Sep 2013 18:02:21 +0000 (-0400) Subject: Fix warnings during final GC of the test suite in python 3.4a1. X-Git-Tag: v3.2.0b1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bd3ef08805e680d4a42835d0e9a3a26594584c2;p=thirdparty%2Ftornado.git Fix warnings during final GC of the test suite in python 3.4a1. 3.4 can GC things that were uncollectable before, like abandoned generators. It also seems generates ResourceWarnings for unclosed files in places where older versions did not. --- diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index d34d8a826..0efef9b32 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -442,8 +442,8 @@ class SyncHTTPClientTest(unittest.TestCase): sock, self.port = bind_unused_port() app = Application([('/', HelloWorldHandler)]) - server = HTTPServer(app, io_loop=self.server_ioloop) - server.add_socket(sock) + self.server = HTTPServer(app, io_loop=self.server_ioloop) + self.server.add_socket(sock) self.server_thread = threading.Thread(target=self.server_ioloop.start) self.server_thread.start() @@ -451,7 +451,10 @@ class SyncHTTPClientTest(unittest.TestCase): self.http_client = HTTPClient() def tearDown(self): - self.server_ioloop.add_callback(self.server_ioloop.stop) + def stop_server(): + self.server.stop() + self.server_ioloop.stop() + self.server_ioloop.add_callback(stop_server) self.server_thread.join() self.http_client.close() self.server_ioloop.close(all_fds=True) diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 915376a71..1e54ea1d2 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -122,9 +122,9 @@ class SimpleHTTPClientTestMixin(object): SimpleAsyncHTTPClient(self.io_loop, force_instance=True)) # different IOLoops use different objects - io_loop2 = IOLoop() - self.assertTrue(SimpleAsyncHTTPClient(self.io_loop) is not - SimpleAsyncHTTPClient(io_loop2)) + with closing(IOLoop()) as io_loop2: + self.assertTrue(SimpleAsyncHTTPClient(self.io_loop) is not + SimpleAsyncHTTPClient(io_loop2)) def test_connection_limit(self): with closing(self.create_client(max_clients=2)) as client: diff --git a/tornado/test/stack_context_test.py b/tornado/test/stack_context_test.py index 26988ddb3..5f62852f6 100644 --- a/tornado/test/stack_context_test.py +++ b/tornado/test/stack_context_test.py @@ -219,12 +219,21 @@ class StackContextTest(AsyncTestCase): def test_yield_in_with(self): @gen.engine def f(): - with StackContext(functools.partial(self.context, 'c1')): - # This yield is a problem: the generator will be suspended - # and the StackContext's __exit__ is not called yet, so - # the context will be left on _state.contexts for anything - # that runs before the yield resolves. - yield gen.Task(self.io_loop.add_callback) + try: + with StackContext(functools.partial(self.context, 'c1')): + # This yield is a problem: the generator will be suspended + # and the StackContext's __exit__ is not called yet, so + # the context will be left on _state.contexts for anything + # that runs before the yield resolves. + yield gen.Task(self.io_loop.add_callback) + except StackContextInconsistentError: + # In python <= 3.3, this suspended generator is never garbage + # collected, so it remains suspended in the 'yield' forever. + # Starting in 3.4, it is made collectable by raising + # a GeneratorExit exception from the yield, which gets + # converted into a StackContextInconsistentError by the + # exit of the 'with' block. + pass with self.assertRaises(StackContextInconsistentError): f() @@ -242,8 +251,11 @@ class StackContextTest(AsyncTestCase): # As above, but with ExceptionStackContext instead of StackContext. @gen.engine def f(): - with ExceptionStackContext(lambda t, v, tb: False): - yield gen.Task(self.io_loop.add_callback) + try: + with ExceptionStackContext(lambda t, v, tb: False): + yield gen.Task(self.io_loop.add_callback) + except StackContextInconsistentError: + pass with self.assertRaises(StackContextInconsistentError): f()