12055: Merge branch 'master' into 12055-nodemanager-ec2-tags
[arvados.git] / services / nodemanager / tests / test_computenode.py
1 #!/usr/bin/env python
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 from __future__ import absolute_import, print_function
7
8 import time
9 import unittest
10
11 import arvados.errors as arverror
12 import mock
13
14 import arvnodeman.computenode as cnode
15 from . import testutil
16
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())
29
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())