2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
11 import arvados.errors as arverror
14 import arvnodeman.computenode as cnode
15 from . import testutil
17 @mock.patch('time.time', return_value=1)
18 class ShutdownTimerTestCase(unittest.TestCase):
19 def test_two_length_window(self, time_mock):
20 timer = cnode.ShutdownTimer(time_mock.return_value, [8, 2])
21 self.assertEqual(481, timer.next_opening())
22 self.assertFalse(timer.window_open())
23 time_mock.return_value += 500
24 self.assertEqual(1081, timer.next_opening())
25 self.assertTrue(timer.window_open())
26 time_mock.return_value += 200
27 self.assertEqual(1081, timer.next_opening())
28 self.assertFalse(timer.window_open())
30 def test_three_length_window(self, time_mock):
31 timer = cnode.ShutdownTimer(time_mock.return_value, [6, 3, 1])
32 self.assertEqual(361, timer.next_opening())
33 self.assertFalse(timer.window_open())
34 time_mock.return_value += 400
35 self.assertEqual(961, timer.next_opening())
36 self.assertTrue(timer.window_open())
37 time_mock.return_value += 200
38 self.assertEqual(961, timer.next_opening())
39 self.assertFalse(timer.window_open())
42 class ArvadosTimestamp(unittest.TestCase):
43 def test_arvados_timestamp(self):
44 self.assertEqual(1527710178, cnode.arvados_timestamp('2018-05-30T19:56:18Z'))
45 self.assertEqual(1527710178.999371, cnode.arvados_timestamp('2018-05-30T19:56:18.999371Z'))