PollMixin: snoop trial's error observer to halt the test early if an error is seen...
authorBrian Warner <warner@lothar.com>
Tue, 23 Jun 2009 02:07:31 +0000 (19:07 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 23 Jun 2009 02:07:31 +0000 (19:07 -0700)
src/allmydata/test/test_storage.py
src/allmydata/util/pollmixin.py

index 1caca2679cea80e9b89538c25c39498cf9e14fec..6ca78cebba256122f6e747b0aec0c825ace3d96f 100644 (file)
@@ -2302,6 +2302,10 @@ class LeaseCrawler(unittest.TestCase, pollmixin.PollMixin, WebRenderingMixin):
         return d
 
     def test_share_corruption(self):
+        self._poll_should_ignore_these_errors = [
+            UnknownMutableContainerVersionError,
+            UnknownImmutableContainerVersionError,
+            ]
         basedir = "storage/LeaseCrawler/share_corruption"
         fileutil.make_dirs(basedir)
         ss = InstrumentedStorageServer(basedir, "\x00" * 20)
index 4f7ab828027307b612e319a69912db60046be510..7b15476f67b13d87ed4d6c33a7905cf8ef33cf99 100644 (file)
@@ -9,6 +9,7 @@ class PollComplete(Exception):
     pass
 
 class PollMixin:
+    _poll_should_ignore_these_errors = []
 
     def poll(self, check_f, pollinterval=0.01, timeout=100):
         # Return a Deferred, then call check_f periodically until it returns
@@ -33,4 +34,17 @@ class PollMixin:
             raise TimeoutError("PollMixin never saw %s return True" % check_f)
         if check_f():
             raise PollComplete()
+        # since PollMixin is mostly used for unit tests, quit if we see any
+        # logged errors. This should give us a nice fast failure, instead of
+        # waiting for a timeout. Tests which use flushLoggedErrors() will
+        # need to warn us by putting the error types they'll be ignoring in
+        # self._poll_should_ignore_these_errors
+        if hasattr(self, "_observer") and hasattr(self._observer, "getErrors"):
+            errs = []
+            for e in self._observer.getErrors():
+                if not e.check(*self._poll_should_ignore_these_errors):
+                    errs.append(e)
+            if errs:
+                print errs
+                self.fail("Errors snooped, terminating early")