From c76d8717152186527ee06eff1924437e23b1ea52 Mon Sep 17 00:00:00 2001 From: Corey Ostrove Date: Sun, 2 Jun 2024 22:03:03 -0600 Subject: [PATCH] Address non-deterministic unit test failure This timer test occasionally fails due to sleep lasting slightly less time than the specified duration. I think this is fundamentally due simply to the relatively sloppy specs on sleep provided by OSes (most are apparently only accurate at the 1-10ms level, and while usually they run long, they can occasionally run short too). --- test/unit/tools/test_opttools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/tools/test_opttools.py b/test/unit/tools/test_opttools.py index 0945b595a..80dcdec6d 100644 --- a/test/unit/tools/test_opttools.py +++ b/test/unit/tools/test_opttools.py @@ -49,8 +49,8 @@ def test_timer(self): timeDict = {} with opt.timed_block('time', timeDict): sleep(duration) - - self.assertGreaterEqual(timeDict['time'], duration) + lt_tol = 1e-3 + self.assertGreaterEqual(timeDict['time'], duration-lt_tol) #sometimes sleeps lasts slightly less than specified duration. tolerance = 0.2 # this should deliberately be large, for repeatability self.assertLessEqual(timeDict['time'], duration + tolerance, "timed block result is greater than {} seconds off".format(tolerance))