4294: added min_nodes config parameter
[arvados.git] / services / nodemanager / tests / testutil.py
index a33f76fe86a62d7e848846d557efed2c2cd03e1e..a1b06583e407dbe22842810dc64aaa7d19bd3d97 100644 (file)
@@ -7,13 +7,15 @@ import time
 import mock
 import pykka
 
+from . import pykka_timeout
+
 no_sleep = mock.patch('time.sleep', lambda n: None)
 
 def arvados_node_mock(node_num=99, job_uuid=None, age=0, **kwargs):
     if job_uuid is True:
         job_uuid = 'zzzzz-jjjjj-jobjobjobjobjob'
     slurm_state = 'idle' if (job_uuid is None) else 'alloc'
-    node = {'uuid': 'zzzzz-yyyyy-12345abcde67890',
+    node = {'uuid': 'zzzzz-yyyyy-{:015x}'.format(node_num),
             'created_at': '2014-01-01T01:02:03Z',
             'modified_at': time.strftime('%Y-%m-%dT%H:%M:%SZ',
                                          time.gmtime(time.time() - age)),
@@ -60,16 +62,24 @@ class MockTimer(object):
 
 class ActorTestMixin(object):
     FUTURE_CLASS = pykka.ThreadingFuture
-    TIMEOUT = 5
+    TIMEOUT = pykka_timeout
 
     def tearDown(self):
         pykka.ActorRegistry.stop_all()
 
-    def wait_for_call(self, mock_func, timeout=TIMEOUT):
+    def stop_proxy(self, proxy):
+        return proxy.actor_ref.stop(timeout=self.TIMEOUT)
+
+    def wait_for_assignment(self, proxy, attr_name, unassigned=None,
+                            timeout=TIMEOUT):
         deadline = time.time() + timeout
-        while (not mock_func.called) and (time.time() < deadline):
-            time.sleep(.1)
-        self.assertTrue(mock_func.called, "{} not called".format(mock_func))
+        while True:
+            loop_timeout = deadline - time.time()
+            if loop_timeout <= 0:
+                self.fail("actor did not assign {} in time".format(attr_name))
+            result = getattr(proxy, attr_name).get(loop_timeout)
+            if result is not unassigned:
+                return result
 
 
 class RemotePollLoopActorTestMixin(ActorTestMixin):