temporary fix for bug in scheduling when at capacity. if no drone has capacity, pick the one with the least load.
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3298 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/drone_manager_unittest.py b/scheduler/drone_manager_unittest.py
new file mode 100644
index 0000000..31a6f4b
--- /dev/null
+++ b/scheduler/drone_manager_unittest.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+
+import unittest
+import common
+from autotest_lib.scheduler import drone_manager, drones
+
+class MockDrone(drones._AbstractDrone):
+ def __init__(self, name, active_processes, max_processes):
+ super(MockDrone, self).__init__()
+ self.name = name
+ self.active_processes = active_processes
+ self.max_processes = max_processes
+
+
+class DroneManager(unittest.TestCase):
+ def setUp(self):
+ self.manager = drone_manager.DroneManager()
+
+
+ def _test_choose_drone_for_execution_helper(self, processes_info_list,
+ requested_processes):
+ for index, process_info in enumerate(processes_info_list):
+ active_processes, max_processes = process_info
+ self.manager._enqueue_drone(MockDrone(index, active_processes,
+ max_processes))
+
+ return self.manager._choose_drone_for_execution(requested_processes)
+
+
+ def test_choose_drone_for_execution(self):
+ drone = self._test_choose_drone_for_execution_helper([(1, 2), (0, 2)],
+ 1)
+ self.assertEquals(drone.name, 1)
+
+
+ def test_choose_drone_for_execution_some_full(self):
+ drone = self._test_choose_drone_for_execution_helper([(0, 1), (1, 3)],
+ 2)
+ self.assertEquals(drone.name, 1)
+
+
+ def test_choose_drone_for_execution_all_full(self):
+ drone = self._test_choose_drone_for_execution_helper([(2, 1), (3, 2)],
+ 1)
+ self.assertEquals(drone.name, 1)
+
+
+if __name__ == '__main__':
+ unittest.main()