showard | e39ebe9 | 2009-06-18 23:14:48 +0000 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import unittest |
| 4 | import common |
| 5 | from autotest_lib.scheduler import drone_manager, drones |
| 6 | |
| 7 | class MockDrone(drones._AbstractDrone): |
| 8 | def __init__(self, name, active_processes, max_processes): |
| 9 | super(MockDrone, self).__init__() |
| 10 | self.name = name |
| 11 | self.active_processes = active_processes |
| 12 | self.max_processes = max_processes |
| 13 | |
| 14 | |
| 15 | class DroneManager(unittest.TestCase): |
| 16 | def setUp(self): |
| 17 | self.manager = drone_manager.DroneManager() |
| 18 | |
| 19 | |
| 20 | def _test_choose_drone_for_execution_helper(self, processes_info_list, |
| 21 | requested_processes): |
| 22 | for index, process_info in enumerate(processes_info_list): |
| 23 | active_processes, max_processes = process_info |
| 24 | self.manager._enqueue_drone(MockDrone(index, active_processes, |
| 25 | max_processes)) |
| 26 | |
| 27 | return self.manager._choose_drone_for_execution(requested_processes) |
| 28 | |
| 29 | |
| 30 | def test_choose_drone_for_execution(self): |
| 31 | drone = self._test_choose_drone_for_execution_helper([(1, 2), (0, 2)], |
| 32 | 1) |
| 33 | self.assertEquals(drone.name, 1) |
| 34 | |
| 35 | |
| 36 | def test_choose_drone_for_execution_some_full(self): |
| 37 | drone = self._test_choose_drone_for_execution_helper([(0, 1), (1, 3)], |
| 38 | 2) |
| 39 | self.assertEquals(drone.name, 1) |
| 40 | |
| 41 | |
| 42 | def test_choose_drone_for_execution_all_full(self): |
| 43 | drone = self._test_choose_drone_for_execution_helper([(2, 1), (3, 2)], |
| 44 | 1) |
| 45 | self.assertEquals(drone.name, 1) |
| 46 | |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | unittest.main() |