12199: Improve race handling in busywait.
authorTom Clegg <tclegg@veritasgenetics.com>
Mon, 12 Feb 2018 22:06:13 +0000 (17:06 -0500)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 12 Feb 2018 22:06:13 +0000 (17:06 -0500)
The previous implementation was "call f() until it's truthy, then
assert f()". The assertion fails if f() returns truthy but then
returns falsy on the next call.

The new implementation doesn't call f() again after it returns truthy
once.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

services/nodemanager/tests/test_daemon.py

index ebe7408e705b02e2d55b2d757ef5367953f23242..50fa0aa68a4fb26c58cdb6978594805e314a7e31 100644 (file)
@@ -23,12 +23,13 @@ class NodeManagerDaemonActorTestCase(testutil.ActorTestMixin,
                                      unittest.TestCase):
 
     def busywait(self, f):
-        n = 0
-        while not f() and n < 200:
+        for n in xrange(200):
+            ok = f()
+            if ok:
+                return
             time.sleep(.1)
             self.daemon.ping().get(self.TIMEOUT)
-            n += 1
-        self.assertTrue(f())
+        self.assertTrue(ok) # always falsy, but not necessarily False
 
     def mock_node_start(self, **kwargs):
         # Make sure that every time the daemon starts a setup actor,