コード例 #1
0
ファイル: test_servers.py プロジェクト: clchiou/garage
 def test_server_exit(self):
     server_task = self.queue.spawn(noop)
     self.assert_state(False, 1, [])
     self.assertIsNone(self.run_supervisor([server_task]))
     self.assert_state(True, 0, [r'no op', r'server task exit: '])
     self.assertIsNone(server_task.get_result_nonblocking())
     self.assertFalse(tasks.get_all_tasks(), [])
コード例 #2
0
 def test_agent_exit(self):
     noop_task = self.agent_queue.spawn(noop)
     self.assert_state(False, 1, False, [])
     self.run_supervisor()
     self.assert_state(True, 0, True,
                       [r'no op', r'graceful exit: agent exit: '])
     self.assertIsNone(noop_task.get_result_nonblocking())
     self.assertFalse(tasks.get_all_tasks())
コード例 #3
0
ファイル: test_servers.py プロジェクト: clchiou/garage
 def test_handler_error(self):
     event = locks.Event()
     server_task = self.queue.spawn(event.wait)
     self.queue.spawn(raises(ValueError('some error')))
     self.assert_state(False, 2, [])
     with self.assertRaises(kernels.KernelTimeout):
         self.run_supervisor([server_task])
     self.assert_state(False, 1, [r'handler task error: '])
     event.set()
     self.assertIsNone(kernels.run(timeout=1))
     self.assert_state(True, 0,
                       [r'handler task error: ', r'server task exit: '])
     self.assertTrue(server_task.get_result_nonblocking())
     self.assertFalse(tasks.get_all_tasks(), [])
コード例 #4
0
ファイル: test_servers.py プロジェクト: clchiou/garage
 def test_server_error(self):
     server_task = self.queue.spawn(raises(ValueError('some error')))
     self.assert_state(False, 1, [])
     with self.assertRaisesRegex(
             servers.ServerError,
             r'server task error: ',
     ):
         self.run_supervisor([server_task])
     self.assert_state(True, 0, [])
     with self.assertRaisesRegex(ValueError, r'some error'):
         server_task.get_result_nonblocking()
     self.assertFalse(tasks.get_all_tasks(), [])
     # Make self._assert_logs.__exit__ happy.
     servers.LOG.debug('dummy')
コード例 #5
0
    def test_get_task(self):
        async def func():
            return tasks.get_current_task()

        self.assertEqual(tasks.get_all_tasks(), [])
        self.assertIsNone(tasks.get_current_task())

        k = kernels.Kernel()
        token = contexts.set_kernel(k)
        try:
            task = k.spawn(func)
            self.assertEqual(tasks.get_all_tasks(), [task])

            k.run(timeout=1)
            self.assertEqual(tasks.get_all_tasks(), [])

            self.assertIs(task, task.get_result_nonblocking())

        finally:
            contexts.KERNEL.reset(token)
            k.close()

        self.assertEqual(tasks.get_all_tasks(), [])
        self.assertIsNone(tasks.get_current_task())
コード例 #6
0
 def test_agent_error(self):
     raises_task = self.agent_queue.spawn(raises(ValueError('some error')))
     self.assert_state(False, 1, False, [])
     self.run_supervisor()
     self.assert_state(True, 0, False, [])
     with self.assertRaisesRegex(
             agents.SupervisorError,
             r'agent err out: ',
     ):
         self.main_task.get_result_nonblocking()
     with self.assertRaisesRegex(ValueError, r'some error'):
         raises_task.get_result_nonblocking()
     self.assertFalse(tasks.get_all_tasks())
     # Make self._assert_logs.__exit__ happy.
     agents.LOG.debug('dummy')
コード例 #7
0
 def test_grace_period_exceeded(self):
     self.graceful_exit.set()
     sleep_task = self.agent_queue.spawn(timers.sleep(99))
     self.assert_state(False, 1, True, [])
     self.main_task = tasks.spawn(
         agents.supervise_agents(self.agent_queue, self.graceful_exit, 0))
     kernels.run(timeout=0.01)
     self.assert_state(True, 0, True, [r'graceful exit: requested by user'])
     with self.assertRaisesRegex(
             agents.SupervisorError,
             r'grace period exceeded',
     ):
         self.main_task.get_result_nonblocking()
     with self.assertRaises(tasks.Cancelled):
         sleep_task.get_result_nonblocking()
     self.assertFalse(tasks.get_all_tasks())
コード例 #8
0
    def test_repeated_signals(self):
        sleep_task = self.agent_queue.spawn(timers.sleep(99))
        self.assert_state(False, 1, False, [])

        self.signal_queue.put_nonblocking(1)
        with self.assertRaises(kernels.KernelTimeout):
            self.run_supervisor()
        self.assert_state(True, 1, True, [r'graceful exit: receive signal: 1'])

        self.signal_queue.put_nonblocking(2)
        kernels.run(timeout=1)
        self.assert_state(True, 0, True, [r'graceful exit: receive signal: 1'])

        with self.assertRaisesRegex(
                agents.SupervisorError,
                r'receive signal during graceful exit: 2',
        ):
            self.main_task.get_result_nonblocking()
        with self.assertRaises(tasks.Cancelled):
            sleep_task.get_result_nonblocking()
        self.assertFalse(tasks.get_all_tasks())
コード例 #9
0
 def test_signal(self):
     self.signal_queue.put_nonblocking(1)
     self.run_supervisor()
     self.assert_state(True, 0, True, [r'graceful exit: receive signal: 1'])
     self.assertIsNone(self.main_task.get_result_nonblocking())
     self.assertFalse(tasks.get_all_tasks())
コード例 #10
0
 def test_graceful_exit_by_user(self):
     self.graceful_exit.set()
     self.run_supervisor()
     self.assert_state(True, 0, True, [r'graceful exit: requested by user'])
     self.assertIsNone(self.main_task.get_result_nonblocking())
     self.assertFalse(tasks.get_all_tasks())