Merge branch 'master' into 4486-document-arv
[arvados.git] / services / nodemanager / tests / test_clientactor.py
index 1e4c40ec6b94227e868880c87b8f9973aa63312d..57a0d32d062b87276af90c5945b0d60ceaba8e88 100644 (file)
@@ -64,6 +64,31 @@ class RemotePollLoopActorTestCase(testutil.RemotePollLoopActorTestMixin,
                         "poll loop died from dead subscriber")
         self.subscriber.assert_called_with('survive2')
 
+    def check_poll_timers(self, *test_times):
+        schedule_mock = self.timer.schedule
+        last_expect = None
+        with mock.patch('time.time') as time_mock:
+            for fake_time, expect_next in test_times:
+                time_mock.return_value = fake_time
+                self.monitor.poll(last_expect).get(self.TIMEOUT)
+                self.assertTrue(schedule_mock.called)
+                self.assertEqual(expect_next, schedule_mock.call_args[0][0])
+                schedule_mock.reset_mock()
+                last_expect = expect_next
+
+    def test_poll_timing_on_consecutive_successes_with_drift(self):
+        self.build_monitor(['1', '2'], poll_wait=3, max_poll_wait=14)
+        self.check_poll_timers((0, 3), (4, 6))
+
+    def test_poll_backoff_on_failures(self):
+        self.build_monitor(self.MockClientError, poll_wait=3, max_poll_wait=14)
+        self.check_poll_timers((0, 6), (6, 18), (18, 32))
+
+    def test_poll_timing_after_error_recovery(self):
+        self.build_monitor(['a', self.MockClientError(), 'b'],
+                           poll_wait=3, max_poll_wait=14)
+        self.check_poll_timers((0, 3), (4, 10), (10, 13))
+
     def test_no_subscriptions_by_key_without_support(self):
         self.build_monitor([])
         with self.assertRaises(AttributeError):