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))
51 def test_job_requesting_max_nodes_accepted(self):
52 servcalc = self.make_calculator([1], max_nodes=4)
53 servlist = self.calculate(servcalc, {'min_nodes': 4})
54 self.assertEqual(4, len(servlist))
56 def test_cheapest_size(self):
57 servcalc = self.make_calculator([2, 4, 1, 3])
58 self.assertEqual(testutil.MockSize(1), servcalc.cheapest_size())
61 class JobQueueMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin,
63 TEST_CLASS = jobqueue.JobQueueMonitorActor
65 class MockCalculator(object):
67 def servers_for_queue(queue):
68 return [testutil.MockSize(n) for n in queue]
71 def build_monitor(self, side_effect, *args, **kwargs):
72 super(JobQueueMonitorActorTestCase, self).build_monitor(*args, **kwargs)
73 self.client.jobs().queue().execute.side_effect = side_effect
75 def test_subscribers_get_server_lists(self):
76 self.build_monitor([{'items': [1, 2]}], self.MockCalculator())
77 self.monitor.subscribe(self.subscriber).get(self.TIMEOUT)
78 self.stop_proxy(self.monitor)
79 self.subscriber.assert_called_with([testutil.MockSize(1),
80 testutil.MockSize(2)])
83 if __name__ == '__main__':