From: Brian Warner Date: Tue, 23 Jun 2009 02:07:31 +0000 (-0700) Subject: PollMixin: snoop trial's error observer to halt the test early if an error is seen... X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/%3C?a=commitdiff_plain;h=699510c8f169f6d709e86d915390cac13efa455c;p=tahoe-lafs%2Ftahoe-lafs.git PollMixin: snoop trial's error observer to halt the test early if an error is seen. This turns a lot of timeouts into fast failures. --- diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 1caca267..6ca78ceb 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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) diff --git a/src/allmydata/util/pollmixin.py b/src/allmydata/util/pollmixin.py index 4f7ab828..7b15476f 100644 --- a/src/allmydata/util/pollmixin.py +++ b/src/allmydata/util/pollmixin.py @@ -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")