From: Ben Darnell Date: Sun, 5 Oct 2014 19:43:05 +0000 (-0400) Subject: Add a test for removing an IOLoop handler from another handler. X-Git-Tag: v4.1.0b1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d572ea2d93bdecda41fa3f949875b8f74e02bf12;p=thirdparty%2Ftornado.git Add a test for removing an IOLoop handler from another handler. Related to #1214. --- diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 110158d12..7eb7594fd 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -334,6 +334,33 @@ class TestIOLoop(AsyncTestCase): with ExpectLog(app_log, "Exception in callback"): self.wait() + @skipIfNonUnix + def test_remove_handler_from_handler(self): + # Create two sockets with simultaneous read events. + client, server = socket.socketpair() + try: + client.send(b'abc') + server.send(b'abc') + + # After reading from one fd, remove the other from the IOLoop. + chunks = [] + def handle_read(fd, events): + chunks.append(fd.recv(1024)) + if fd is client: + self.io_loop.remove_handler(server) + else: + self.io_loop.remove_handler(client) + self.io_loop.add_handler(client, handle_read, self.io_loop.READ) + self.io_loop.add_handler(server, handle_read, self.io_loop.READ) + self.io_loop.call_later(0.01, self.stop) + self.wait() + + # Only one fd was read; the other was cleanly removed. + self.assertEqual(chunks, [b'abc']) + finally: + client.close() + server.close() + # Deliberately not a subclass of AsyncTestCase so the IOLoop isn't # automatically set as current.