3 from __future__ import absolute_import, print_function
7 import arvnodeman.jobqueue as jobqueue
10 class ServerCalculatorTestCase(unittest.TestCase):
11 def make_calculator(self, factors, **kwargs):
12 return jobqueue.ServerCalculator(
13 [(testutil.MockSize(n), {'cores': n}) for n in factors], **kwargs)
15 def calculate(self, servcalc, *constraints):
16 return servcalc.servers_for_queue(
17 [{'runtime_constraints': cdict} for cdict in constraints])
19 def test_empty_queue_needs_no_servers(self):
20 servcalc = self.make_calculator([1])
21 self.assertEqual([], servcalc.servers_for_queue([]))
23 def test_easy_server_count(self):
24 servcalc = self.make_calculator([1])
25 servlist = self.calculate(servcalc, {'min_nodes': 3})
26 self.assertEqual(3, len(servlist))
28 def test_implicit_server_count(self):
29 servcalc = self.make_calculator([1])
30 servlist = self.calculate(servcalc, {}, {'min_nodes': 3})
31 self.assertEqual(4, len(servlist))
33 def test_bad_min_nodes_override(self):
34 servcalc = self.make_calculator([1])
35 servlist = self.calculate(servcalc,
36 {'min_nodes': -2}, {'min_nodes': 'foo'})
37 self.assertEqual(2, len(servlist))
39 def test_ignore_unsatisfiable_jobs(self):
40 servcalc = self.make_calculator([1], max_nodes=9)
41 servlist = self.calculate(servcalc,
42 {'min_cores_per_node': 2},
43 {'min_ram_mb_per_node': 256},
46 {'min_scratch_mb_per_node': 200})
47 self.assertEqual(6, len(servlist))
50 class JobQueueMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin,
52 TEST_CLASS = jobqueue.JobQueueMonitorActor
54 class MockCalculator(object):
56 def servers_for_queue(queue):
57 return [testutil.MockSize(n) for n in queue]
60 def build_monitor(self, side_effect, *args, **kwargs):
61 super(JobQueueMonitorActorTestCase, self).build_monitor(*args, **kwargs)
62 self.client.jobs().queue().execute.side_effect = side_effect
64 def test_subscribers_get_server_lists(self):
65 self.build_monitor([{'items': [1, 2]}], self.MockCalculator())
66 self.monitor.subscribe(self.subscriber)
67 self.wait_for_call(self.subscriber)
68 self.subscriber.assert_called_with([testutil.MockSize(1),
69 testutil.MockSize(2)])
72 if __name__ == '__main__':