3 from __future__ import absolute_import, print_function
8 import arvados.errors as arverror
11 import arvnodeman.computenode as cnode
12 from . import testutil
14 @mock.patch('time.time', return_value=1)
15 class ShutdownTimerTestCase(unittest.TestCase):
16 def test_two_length_window(self, time_mock):
17 timer = cnode.ShutdownTimer(time_mock.return_value, [8, 2])
18 self.assertEqual(481, timer.next_opening())
19 self.assertFalse(timer.window_open())
20 time_mock.return_value += 500
21 self.assertEqual(1081, timer.next_opening())
22 self.assertTrue(timer.window_open())
23 time_mock.return_value += 200
24 self.assertEqual(1081, timer.next_opening())
25 self.assertFalse(timer.window_open())
27 def test_three_length_window(self, time_mock):
28 timer = cnode.ShutdownTimer(time_mock.return_value, [6, 3, 1])
29 self.assertEqual(361, timer.next_opening())
30 self.assertFalse(timer.window_open())
31 time_mock.return_value += 400
32 self.assertEqual(961, timer.next_opening())
33 self.assertTrue(timer.window_open())
34 time_mock.return_value += 200
35 self.assertEqual(961, timer.next_opening())
36 self.assertFalse(timer.window_open())