Пример #1
0
    def fetch_and_assert(self, external: bool, cached: bool) -> None:
        """
        This test offloads multiple tasks and asserts that fetch returns the according task
        :param external: selects whether the worker should be run in an external process or not.
        :param cached: selects whether the task should only reside in cache or not
        :return: None
        """
        tid1 = offload_task(sleep_time=6, ext_process=external, cached=cached)
        tid2 = offload_task(sleep_time=4, ext_process=external, cached=cached)
        tid3 = offload_task(sleep_time=2, ext_process=external, cached=cached)

        t1 = django_q.fetch(tid1, wait=WAIT_TIME, cached=cached)
        assert t1 is not None
        assert t1.success is True
        assert t1.id == tid1

        t2 = django_q.fetch(tid2, wait=WAIT_TIME, cached=cached)
        assert t2 is not None
        assert t2.success is True
        assert t2.id == tid2

        t3 = django_q.fetch(tid3, wait=WAIT_TIME, cached=cached)
        assert t3 is not None
        assert t3.success is True
        assert t3.id == tid3
Пример #2
0
 def test_fetch_one(self, cached):
     """
     This test offloads and fetches only one task per test run.
     :param cached: defines whether the cache should be used.
     :return: None
     """
     tid = offload_task(sleep_time=3, ext_process=False, cached=cached)
     task = django_q.fetch(tid, wait=WAIT_TIME, cached=cached)
     assert task is not None