Example #1
0
 def test_loop_report_demand(self):
     self.assertEqual(get_worker_cnt(self.queue), 0)
     self.planner.strategy.apply = MagicMock(return_value=1)
     self.planner.start()
     wait_condition_till_timeout(lambda: True, 1)
     self.planner.strategy.apply.assert_called()
     self.assertTrue(get_worker_cnt(self.queue) > 0)
Example #2
0
 def test_loop_report_demand(self):
     self.assertEqual(get_worker_cnt(self.queue), 0)
     self.planner.strategy.apply = MagicMock(return_value=1)
     self.planner.start()
     wait_condition_till_timeout(lambda: True, 1)
     self.planner.strategy.apply.assert_called()
     self.assertTrue(get_worker_cnt(self.queue) > 0)
Example #3
0
 def test_loop_raise_exception(self):
     self.assertEqual(get_worker_cnt(self.queue), 0)
     self.planner.strategy.apply = MagicMock(return_value='invalid string value')
     self.planner.start()
     wait_condition_till_timeout(lambda: True, 1)
     self.planner.strategy.apply.assert_called()
     self.assertTrue(get_worker_cnt(self.queue) == 0)
Example #4
0
 def test_loop_raise_exception(self):
     self.assertEqual(get_worker_cnt(self.queue), 0)
     self.planner.strategy.apply = MagicMock(
         return_value='invalid string value')
     self.planner.start()
     wait_condition_till_timeout(lambda: True, 1)
     self.planner.strategy.apply.assert_called()
     self.assertTrue(get_worker_cnt(self.queue) == 0)
Example #5
0
 def stop(self):
     if not self.alive:
         return
     self.__shutdown.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         self.force_quit()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise PlannerException('Could not stop planner %s' % self.queue)
     debug('[Planner] - [Stop] - %s' % self)
Example #6
0
 def stop(self):
     if not self.alive:
         return
     self.__shutdown.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         self.force_quit()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise PlannerException('Could not stop planner %s' % self.queue)
     debug('[Planner] - [Stop] - %s' % self)
Example #7
0
 def test_register_to_hub(self):
     reset()
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise CouldNotStartException('hub')
     self.assertEqual(len(MACHINES), 0)
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.assertEqual(len(MACHINES), 1)
     self.assertEqual(MACHINES.keys(), [self.guard.machine.id])
Example #8
0
 def test_register_to_hub(self):
     reset()
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise CouldNotStartException('hub')
     self.assertEqual(len(MACHINES), 0)
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.assertEqual(len(MACHINES), 1)
     self.assertEqual(MACHINES.keys(), [self.guard.machine.id])
Example #9
0
 def test_heart_beat(self):
     PLAN = {'q1': {self.guard.machine.id: 1}}
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise CouldNotStartException('hub')
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     Hub.report_demand(InstructionType.WORKER, 'q1', 2)
     _org_receive_order = commands.receive_order
     commands.receive_order = MagicMock()
     time.sleep(2)
     commands.receive_order.assert_called()
     commands.receive_order = _org_receive_order
Example #10
0
 def test_heart_beat(self):
     PLAN = {'q1': {self.guard.machine.id: 1}}
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise CouldNotStartException('hub')
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     Hub.report_demand(InstructionType.WORKER, 'q1', 2)
     _org_receive_order = commands.receive_order
     commands.receive_order = MagicMock()
     time.sleep(2)
     commands.receive_order.assert_called()
     commands.receive_order = _org_receive_order
Example #11
0
 def test_worker_pool_grow(self):
     planner = PlannerPool.get_or_create_planner(self.queue, self.app, self.strategy_name, self.labels)
     planner.loop_interval = 0.1
     planner.strategy.apply = PickableMock(return_value=self.worker_cnt)
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         CouldNotStartException('hub')
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.guard.pool.get_or_create_pool_name = PickableMock(return_value=self.queue)
     time.sleep(1)
     self.guard.pool.grow.assert_called_with(self.queue, self.worker_cnt)
     planner.stop()
Example #12
0
 def test_worker_pool_grow(self):
     planner = PlannerPool.get_or_create_planner(self.queue, self.app,
                                                 self.strategy_name,
                                                 self.labels)
     planner.loop_interval = 0.1
     planner.strategy.apply = PickableMock(return_value=self.worker_cnt)
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         CouldNotStartException('hub')
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.guard.pool.get_or_create_pool_name = PickableMock(
         return_value=self.queue)
     time.sleep(1)
     self.guard.pool.grow.assert_called_with(self.queue, self.worker_cnt)
     planner.stop()
Example #13
0
 def test_start_stop(self):
     self.guard._register_to_hub = MagicMock()
     self.guard.heartbeat = MagicMock()
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.assertTrue(self.guard.alive)
     self.guard.heartbeat.assert_called()
     self.guard.stop()
     self.assertFalse(self.guard.alive)
Example #14
0
 def test_start_stop(self):
     self.guard._register_to_hub = MagicMock()
     self.guard.heartbeat = MagicMock()
     start_daemon_thread(self.guard.start)
     if wait_condition_till_timeout(self.guard.is_alive, 5, False):
         raise CouldNotStartException('guard')
     self.assertTrue(self.guard.alive)
     self.guard.heartbeat.assert_called()
     self.guard.stop()
     self.assertFalse(self.guard.alive)
Example #15
0
 def stop(self):
     '''
     Step 1. Unregister to hub (todo)
     Step 2. Stop rpc server
     Step 3. Stop the loop
     '''
     if self.rpc_server.alive:
         self.rpc_server.stop()
     self.__shutdown_guard.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise CouldNotStopException('guard')
Example #16
0
 def stop(self):
     '''
     Step 1. Unregister to hub (todo)
     Step 2. Stop rpc server
     Step 3. Stop the loop
     '''
     if self.rpc_server.alive:
         self.rpc_server.stop()
     self.__shutdown_guard.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise CouldNotStopException('guard')
Example #17
0
 def stop(self):
     '''
     Step 1. Stop all planner
     Step 2. Stop rpc server
     Step 3. Stop the loop
     '''
     reset()
     from popcorn.apps.planner import PlannerPool
     PlannerPool.stop()
     if self.rpc_server.alive:
         self.rpc_server.stop()
     self.__shutdown_hub.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise CouldNotStopException('hub')
Example #18
0
 def stop(self):
     '''
     Step 1. Stop all planner
     Step 2. Stop rpc server
     Step 3. Stop the loop
     '''
     reset()
     from popcorn.apps.planner import PlannerPool
     PlannerPool.stop()
     if self.rpc_server.alive:
         self.rpc_server.stop()
     self.__shutdown_hub.set()
     if wait_condition_till_timeout(self.is_alive, 10):
         raise CouldNotStopException('hub')
Example #19
0
 def test_start_stop(self):
     self.hub.analyze_demand = MagicMock()
     self.hub.send_order_to_guard = MagicMock()
     self.hub.load_balancing = MagicMock()
     self.assertFalse(self.hub.alive)
     self.assertFalse(self.hub.rpc_server.alive)
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise 'could not start hub'
     self.assertTrue(self.hub.alive)
     self.assertTrue(self.hub.rpc_server.alive)
     self.hub.analyze_demand.assert_called()
     self.hub.send_order_to_guard.assert_called()
     self.hub.load_balancing.assert_not_called()
     self.hub.stop()
     self.assertFalse(self.hub.alive)
     self.assertFalse(self.hub.rpc_server.alive)
Example #20
0
 def test_force_quite(self):
     self.planner.start()
     self.assertTrue(self.planner.alive)
     self.planner.force_quit()
     wait_condition_till_timeout(self.planner.is_alive, 10)
     self.assertFalse(self.planner.alive)
Example #21
0
 def test_force_quite(self):
     self.planner.start()
     self.assertTrue(self.planner.alive)
     self.planner.force_quit()
     wait_condition_till_timeout(self.planner.is_alive, 10)
     self.assertFalse(self.planner.alive)
Example #22
0
 def test_start_default_planner(self):
     start_daemon_thread(self.hub.start)
     if wait_condition_till_timeout(self.hub.is_alive, 5, False):
         raise 'could not start hub'
     self.assertEqual(PlannerPool.pool.keys(), self.app.conf.config['DEFAULT_QUEUE'].keys())