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 [{'uuid': 'zzzzz-jjjjj-{:015x}'.format(index),
18 'runtime_constraints': cdict}
19 for index, cdict in enumerate(constraints)])
21 def test_empty_queue_needs_no_servers(self):
22 servcalc = self.make_calculator([1])
23 self.assertEqual([], servcalc.servers_for_queue([]))
25 def test_easy_server_count(self):
26 servcalc = self.make_calculator([1])
27 servlist = self.calculate(servcalc, {'min_nodes': 3})
28 self.assertEqual(3, len(servlist))
30 def test_implicit_server_count(self):
31 servcalc = self.make_calculator([1])
32 servlist = self.calculate(servcalc, {}, {'min_nodes': 3})
33 self.assertEqual(4, len(servlist))
35 def test_bad_min_nodes_override(self):
36 servcalc = self.make_calculator([1])
37 servlist = self.calculate(servcalc,
38 {'min_nodes': -2}, {'min_nodes': 'foo'})
39 self.assertEqual(2, len(servlist))
41 def test_ignore_unsatisfiable_jobs(self):
42 servcalc = self.make_calculator([1], max_nodes=9)
43 servlist = self.calculate(servcalc,
44 {'min_cores_per_node': 2},
45 {'min_ram_mb_per_node': 256},
48 {'min_scratch_mb_per_node': 200})
49 self.assertEqual(6, len(servlist))
52 class JobQueueMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin,
54 TEST_CLASS = jobqueue.JobQueueMonitorActor
56 class MockCalculator(object):
58 def servers_for_queue(queue):
59 return [testutil.MockSize(n) for n in queue]
62 def build_monitor(self, side_effect, *args, **kwargs):
63 super(JobQueueMonitorActorTestCase, self).build_monitor(*args, **kwargs)
64 self.client.jobs().queue().execute.side_effect = side_effect
66 def test_subscribers_get_server_lists(self):
67 self.build_monitor([{'items': [1, 2]}], self.MockCalculator())
68 self.monitor.subscribe(self.subscriber).get(self.TIMEOUT)
69 self.stop_proxy(self.monitor)
70 self.subscriber.assert_called_with([testutil.MockSize(1),
71 testutil.MockSize(2)])
74 if __name__ == '__main__':