]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a test for removing an IOLoop handler from another handler.
authorBen Darnell <ben@bendarnell.com>
Sun, 5 Oct 2014 19:43:05 +0000 (15:43 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 5 Oct 2014 19:43:05 +0000 (15:43 -0400)
Related to #1214.

tornado/test/ioloop_test.py

index 110158d12443ea42bf704389d0f8ee91228aff67..7eb7594fd32448c27bca7ab0c29ca979177be827 100644 (file)
@@ -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.