Skip to content

Commit

Permalink
Address non-deterministic unit test failure
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Corey Ostrove committed Jun 3, 2024
1 parent 981762f commit c76d871
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/unit/tools/test_opttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit c76d871

Please sign in to comment.