[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Always test for lingering threads



commit f4b77a2c9194aa964aec0e633255e549186b7f2d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jul 14 14:54:01 2020 -0700

    Always test for lingering threads
    
    Our unit tests are just as liable to orphan threads as our integration tests.
    It's confusing to only detect unit test leaks when running them along side our
    integration tests, so making this check independent of which test suite we run.
---
 run_tests.py                  | 15 ++++++---------
 stem/descriptor/remote.py     |  3 +++
 test/unit/util/synchronous.py |  4 ++++
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index fd46211f..c738f9b8 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -321,18 +321,15 @@ def main():
         integ_runner.stop()
         println()
 
-        # We should have joined on all threads. If not then that indicates a
-        # leak that could both likely be a bug and disrupt further targets.
+  # ensure that we join all our threads
 
-        active_threads = threading.enumerate()
+  active_threads = threading.enumerate()
 
-        if len(active_threads) > 1:
-          println('Threads lingering after test run:', ERROR)
+  if len(active_threads) > 1:
+    println('Threads lingering after test run:', ERROR)
 
-          for lingering_thread in active_threads:
-            println('  %s' % lingering_thread, ERROR)
-
-          break
+    for lingering_thread in active_threads:
+      println('  %s' % lingering_thread, ERROR)
 
   static_check_issues = {}
 
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index ad6a02ab..942d81e9 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -369,6 +369,7 @@ class Query(Synchronous):
     super(Query, self).__init__()
 
     if not resource.startswith('/'):
+      self.stop()
       raise ValueError("Resources should start with a '/': %s" % resource)
 
     if resource.endswith('.z'):
@@ -379,6 +380,7 @@ class Query(Synchronous):
     elif isinstance(compression, stem.descriptor._Compression):
       compression = [compression]  # caller provided only a single option
     else:
+      self.stop()
       raise ValueError('Compression should be a list of stem.descriptor.Compression, was %s (%s)' % (compression, type(compression).__name__))
 
     if Compression.ZSTD in compression and not Compression.ZSTD.available:
@@ -402,6 +404,7 @@ class Query(Synchronous):
         if isinstance(endpoint, (stem.ORPort, stem.DirPort)):
           self.endpoints.append(endpoint)
         else:
+          self.stop()
           raise ValueError("Endpoints must be an stem.ORPort or stem.DirPort. '%s' is a %s." % (endpoint, type(endpoint).__name__))
 
     self.resource = resource
diff --git a/test/unit/util/synchronous.py b/test/unit/util/synchronous.py
index d99da922..602d81f4 100644
--- a/test/unit/util/synchronous.py
+++ b/test/unit/util/synchronous.py
@@ -189,6 +189,8 @@ class TestSynchronous(unittest.TestCase):
       self.assertTrue(instance.called_enter)
       self.assertTrue(instance.called_exit)
 
+      instance.stop()
+
     async def async_test():
       instance = Demo()
 
@@ -202,6 +204,8 @@ class TestSynchronous(unittest.TestCase):
       self.assertTrue(instance.called_enter)
       self.assertTrue(instance.called_exit)
 
+      instance.stop()
+
     sync_test()
     asyncio.run(async_test())
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits