Пример #1
0
    def test_heartbeat_cancel(self):
        heartbeat = FakeHeartbeatCancel(max_count=10)
        heartbeater = HeartbeatProcess(heartbeat, interval=0.1)
        token = uuid4()

        heartbeater.run(token, FakeTask('test_task'))
        self.assertEqual(heartbeat._token, token)
Пример #2
0
    def test_heartbeat_doesnotexist_error(self):
        error_type = 'Unknown execution: blah'
        heartbeat = FakeHeartbeatRaises(
            swf.exceptions.DoesNotExistError('error', error_type), 10)
        heartbeater = HeartbeatProcess(heartbeat, interval=0.1)
        token = uuid4()

        heartbeater.run(token, FakeTask('test_task'))
        self.assertEqual(heartbeat._token, token)
Пример #3
0
 def test_heartbeat_ok(self):
     heartbeat = FakeHeartbeat(max_count=1)
     heartbeater = HeartbeatProcess(heartbeat, interval=0.1)
     token = uuid4()
     try:
         heartbeater.run(token, FakeTask('test_task'))
     except StopIteration:
         pass
     self.assertEqual(heartbeat._token, token)
Пример #4
0
 def test_heartbeat_running(self):
     max_count = 3
     heartbeat = FakeHeartbeat(max_count)
     heartbeater = HeartbeatProcess(heartbeat, interval=0.1)
     token = uuid4()
     try:
         heartbeater.run(token, FakeTask("test_task"))
     except StopIteration:
         pass
     self.assertEqual(heartbeat._max_count, max_count)
     self.assertEqual(heartbeat._token, token)
Пример #5
0
    def test_heartbeat_process_kill_parent(self):
        heartbeat = FakeHeartbeat(1000)
        heartbeater = HeartbeatProcess(heartbeat, interval=0.1)

        token = uuid4()
        task = FakeTask('test_task')

        result_queue = mp.Queue()
        handler = FakeTaskHandler(heartbeater.run, (token, task), {},
                                  result_queue)
        handler_process = mp.Process(target=handler)

        handler_process.start()
        time.sleep(2)
        heartbeat_pid = result_queue.get()
        handler_process.terminate()
        os.kill(handler_process.pid, signal.SIGQUIT)
        handler_process.join()
        time.sleep(2)
        with self.assertRaises(OSError):
            os.kill(heartbeat_pid, signal.SIGKILL)
Пример #6
0
 def test_heartbeat_non_int(self):
     with self.assertRaises(ValueError):
         HeartbeatProcess(lambda *args: None, interval='NOT_AN_INTEGER')
Пример #7
0
 def test_heartbeat_0(self):
     with self.assertRaises(ValueError):
         HeartbeatProcess(lambda *args: None, interval=0)