Beispiel #1
0
    def test_tm_expensive_stop(self):

        expensive_event = threading.Event()
        fail_event = threading.Event()

        num_tasks = 4
        jobs = 16

        tm = TaskManager()
        tm.disable_keep_going()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.add_task(0, num_tasks, _do_fail, 1, fail_event)

        tm.start(jobs)

        fail_event.wait()

        tm.add_expensive_task(num_tasks + 1, _do_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        self.assertEqual(len(results), num_tasks + 1)
        task_ids = sorted(result.task_id for result in results)
        self.assertEqual(task_ids, list(range(num_tasks + 1)))
    def test_tm_expensive_stop(self):

        expensive_event = threading.Event()
        fail_event = threading.Event()

        num_tasks = 4
        jobs = 16

        tm = TaskManager()
        tm.disable_keep_going()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.add_task(0, num_tasks, _do_fail, 1, fail_event)

        tm.start(jobs)

        fail_event.wait()

        tm.add_expensive_task(num_tasks + 1, _do_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        self.assertEqual(len(results), num_tasks + 1)
        task_ids = sorted(result.task_id for result in results)
        self.assertEqual(task_ids, list(range(num_tasks + 1)))
Beispiel #3
0
    def test_tm_expensive_keep_going(self):

        expensive_event = threading.Event()

        num_tasks = 8
        jobs = 16

        tm = TaskManager()
        tm.disable_backtrace()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.add_task(0, num_tasks, _do_fail, 1)

        tm.start(jobs)
        time.sleep(0.25)

        tm.add_expensive_task(num_tasks + 1, _do_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        self.assertEqual(len(results), num_tasks + 2)
    def test_tm_expensive_keep_going(self):

        expensive_event = threading.Event()

        num_tasks = 8
        jobs = 16

        tm = TaskManager()
        tm.disable_backtrace()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.add_task(0, num_tasks, _do_fail, 1)

        tm.start(jobs)
        time.sleep(0.25)

        tm.add_expensive_task(num_tasks + 1, _do_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        self.assertEqual(len(results), num_tasks + 2)
Beispiel #5
0
    def test_tm_expensive_success(self):

        expensive_event = threading.Event()

        num_tasks = 8
        jobs = 16

        tm = TaskManager()
        tm.disable_keep_going()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.start(jobs)
        time.sleep(0.25)

        expensive_task_ids = set()

        for i in range(num_tasks, num_tasks * 2):
            if i % 2:
                expensive_task_ids.add(i)
                tm.add_expensive_task(i, _do_expensive, expensive_event)
            else:
                tm.add_task(0, i, _do_non_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        for result in results:
            self.assertFalse(result.is_failed(), str(result))

        self.assertEqual(len(results), num_tasks * 2)

        task_ids = [result.task_id for result in results]

        finished_expensive_tasks = set(task_ids[-len(expensive_task_ids):])

        self.assertEqual(finished_expensive_tasks, expensive_task_ids)
    def test_tm_expensive_success(self):

        expensive_event = threading.Event()

        num_tasks = 8
        jobs = 16

        tm = TaskManager()
        tm.disable_keep_going()

        for i in range(num_tasks):
            tm.add_task(0, i, _do_non_expensive, expensive_event)

        tm.start(jobs)
        time.sleep(0.25)

        expensive_task_ids = set()

        for i in range(num_tasks, num_tasks * 2):
            if i % 2:
                expensive_task_ids.add(i)
                tm.add_expensive_task(i, _do_expensive, expensive_event)
            else:
                tm.add_task(0, i, _do_non_expensive, expensive_event)

        results = self.get_done_tasks(tm)

        for result in results:
            self.assertFalse(result.is_failed(), str(result))

        self.assertEqual(len(results), num_tasks * 2)

        task_ids = [result.task_id for result in results]

        finished_expensive_tasks = set(task_ids[-len(expensive_task_ids):])

        self.assertEqual(finished_expensive_tasks, expensive_task_ids)