Exemple #1
0
 def test_taskhandler_04(self):
     """Test for accessing the first entry."""
     r = add2(2, 2)
     p = mult(2, 2)
     th = TaskHandler()
     task = th.get_next_task()
     assert task.function == 'add2_delayed'
Exemple #2
0
    def test_periodic_task01(self):
        @periodic_task(seconds=0.02, start_now=True)
        def gettime():
            return time.time()

        _ = gettime()
        th = TaskHandler()
        task = th.get_next_task()
        assert task is not None
Exemple #3
0
 def test_taskhandler_08(self, ttl, result):
     """test ttl."""
     r = add4(2, 3)
     th = TaskHandler()
     task = th.get_next_task()
     th.handle_task(task)
     time.sleep(ttl)
     clean_queue()
     assert r.result == result
Exemple #4
0
 def test_taskhandler_06(self, delay, ready):
     """test delay."""
     th = TaskHandler()
     r = mult2(2, 2)
     time.sleep(delay)
     task = th.get_next_task()
     if task:
         th.handle_task(task)
     assert r.ready is ready
Exemple #5
0
 def test_taskhandler_05(self, a, b, result, status, ready):
     """test error handling."""
     r = add2(a, b)
     th = TaskHandler()
     task = th.get_next_task()
     th.handle_task(task)
     assert task.status == status
     assert r.status == status
     assert r.result == result
     assert r.ready is True
Exemple #6
0
    def test_periodic_task02(self):
        @periodic_task(seconds=0.02, start_now=False)
        def gettime():
            return time.time()

        _ = gettime()
        th = TaskHandler()
        task = th.get_next_task()
        assert task is None
        # wait shorter than timedelta and try again.
        # result should not change.
        time.sleep(0.01)
        task = th.get_next_task()
        assert task is None
        # now the task should be available.
        time.sleep(0.02)
        task = th.get_next_task()
        assert task is not None
Exemple #7
0
 def test_taskhandler_07(self):
     """test retries."""
     r = add3(2, 'c')
     th = TaskHandler()
     task = th.get_next_task()
     th.handle_task(task)
     assert r.status == WAITING
     # should be false because the task is rescheduled
     assert r.ready is False
     time.sleep(1)
     task = th.get_next_task()
     # should be None becaus schedule delay is 1 sec.
     assert task is None
     time.sleep(1.5)
     task = th.get_next_task()
     assert task is not None
     th.handle_task(task)
     # now status should be ERROR and task is done
     assert r.status == ERROR
     assert r.ready is True
Exemple #8
0
 def test_taskhandler_01(self):
     """should return None if no task found."""
     th = TaskHandler()
     assert th.get_next_task() is None
Exemple #9
0
 def test_taskhandler_03(self):
     """Test for accessing this entry."""
     r = add2(2, 2)
     th = TaskHandler()
     task = th.get_next_task()
     assert task.status == RUNNING