]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
asyncio_test: Use inequality when checking thread leaks
authorBen Darnell <ben@bendarnell.com>
Mon, 19 Jun 2023 19:28:45 +0000 (15:28 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 19 Jun 2023 19:34:00 +0000 (15:34 -0400)
Sometimes we have a net reduction in the thread count
because there was an extra thread running at the time captured
the starting count, so use inequality instead of exact matches.

tornado/test/asyncio_test.py

index e4c603aedf418e23688f01e36bc28a8eebeb05d7..4eda9395c88bcdc30abd24a334b8bbef13ba826e 100644 (file)
@@ -171,13 +171,15 @@ class SelectorThreadLeakTest(unittest.TestCase):
         # For some reason we see transient failures here, but I haven't been able
         # to catch it to identify which thread is causing it. Whatever thread it
         # is, it appears to quickly clean up on its own, so just retry a few times.
+        # At least some of the time the errant thread was running at the time we
+        # captured self.orig_thread_count, so use inequalities.
         deadline = time.time() + 1
         while time.time() < deadline:
             threads = list(threading.enumerate())
-            if len(threads) == self.orig_thread_count:
+            if len(threads) <= self.orig_thread_count:
                 break
             time.sleep(0.1)
-        self.assertEqual(self.orig_thread_count, len(threads), threads)
+        self.assertLessEqual(len(threads), self.orig_thread_count, threads)
 
     async def dummy_tornado_coroutine(self):
         # Just access the IOLoop to initialize the selector thread.