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

[tor-commits] [stem/master] Running test_basic_example() multiple times



commit 2f8a3c838fd63a83a6087313b5a3f52160d2e4fb
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 11 13:17:09 2012 -0700

    Running test_basic_example() multiple times
    
    Rerunning the test_basic_example() test fifteen times to make it more sensetive
    to concurrency issues. It now fails consistently! (... yay?)
---
 stem/descriptor/reader.py       |    2 +-
 test/integ/descriptor/reader.py |   31 +++++++++++++++++--------------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 018adc7..a8f3284 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -287,7 +287,7 @@ class DescriptorReader(threading.Thread):
           yield self._unreturned_descriptors.get_nowait()
         except Queue.Empty:
           # if we've finished and there aren't any descriptors then we're done
-          if not self._is_reading.isSet(): break
+          if not self._is_reading.isSet() and self._unreturned_descriptors.empty(): break
           
           self._iter_notice.wait()
           self._iter_notice.clear()
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 24786b7..2568262 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -122,20 +122,23 @@ class TestDescriptorReader(unittest.TestCase):
     with open(descriptor_path) as descriptor_file:
       descriptor_entries.append(descriptor_file.read())
     
-    reader = stem.descriptor.reader.DescriptorReader([DESCRIPTOR_TEST_DATA])
-    
-    with reader:
-      for descriptor in reader:
-        descriptor_str = str(descriptor)
-        
-        if descriptor_str in descriptor_entries:
-          descriptor_entries.remove(descriptor_str)
-        else:
-          # iterator is providing output that we didn't expect
-          self.fail()
-    
-    # check that we've seen all of the descriptor_entries
-    self.assertTrue(len(descriptor_entries) == 0)
+    # running this test multiple times to flush out concurrency issues
+    for i in xrange(15):
+      reader = stem.descriptor.reader.DescriptorReader([DESCRIPTOR_TEST_DATA])
+      remaining_entries = list(descriptor_entries)
+      
+      with reader:
+        for descriptor in reader:
+          descriptor_str = str(descriptor)
+          
+          if descriptor_str in remaining_entries:
+            remaining_entries.remove(descriptor_str)
+          else:
+            # iterator is providing output that we didn't expect
+            self.fail()
+      
+      # check that we've seen all of the descriptor_entries
+      self.assertTrue(len(remaining_entries) == 0)
   
   def test_stop(self):
     """



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