9120: search_for_now falls back to real driver methods when needed.
[arvados.git] / services / nodemanager / tests / testutil.py
index b376ca792a01e9bd9a8aecf5ee782982168e6174..1b6aab3cafed16cfc0960d1a39a32d669fe53ffb 100644 (file)
@@ -119,6 +119,13 @@ class ActorTestMixin(object):
             if result is not unassigned:
                 return result
 
+    def busywait(self, f):
+        n = 0
+        while not f() and n < 10:
+            time.sleep(.1)
+            n += 1
+        self.assertTrue(f())
+
 
 class DriverTestMixin(object):
     def setUp(self):
@@ -143,10 +150,10 @@ class DriverTestMixin(object):
             self.assertTrue(self.driver_mock.called)
             self.assertIs(driver.real, driver_mock2)
 
-    def test_create_can_find_node_after_timeout(self):
-        driver = self.new_driver()
+    def test_create_can_find_node_after_timeout(self, create_kwargs={}, node_extra={}):
+        driver = self.new_driver(create_kwargs=create_kwargs)
         arv_node = arvados_node_mock()
-        cloud_node = cloud_node_mock()
+        cloud_node = cloud_node_mock(**node_extra)
         cloud_node.name = driver.create_cloud_name(arv_node)
         create_method = self.driver_mock().create_node
         create_method.side_effect = cloud_types.LibcloudError("fake timeout")
@@ -166,6 +173,20 @@ class DriverTestMixin(object):
             driver.create_node(MockSize(1), arv_node)
         self.assertIs(create_method.side_effect, exc_test.exception)
 
+    def check_node_found_after_timeout_has_fixed_size(self, size, cloud_node,
+                                                      create_kwargs={}):
+        # This method needs to be called explicitly by driver test suites
+        # that need it.
+        self.driver_mock().list_sizes.return_value = [size]
+        driver = self.new_driver(create_kwargs=create_kwargs)
+        arv_node = arvados_node_mock()
+        cloud_node.name = driver.create_cloud_name(arv_node)
+        create_method = self.driver_mock().create_node
+        create_method.side_effect = cloud_types.LibcloudError("fake timeout")
+        self.driver_mock().list_nodes.return_value = [cloud_node]
+        actual = driver.create_node(size, arv_node)
+        self.assertIs(size, actual.size)
+
 
 class RemotePollLoopActorTestMixin(ActorTestMixin):
     def build_monitor(self, *args, **kwargs):