Пример #1
0
    def test_single_job_with_exception(self):
        wp = WorkerPool(nworkers=1)

        wp.submit(job_no_ctx, 10, 10, True)

        futs = wp.wait()
        self.assertEqual(len(futs), 1)
        for fut in futs:
            self.assertRaises(Exception, fut.result)
Пример #2
0
    def test_single_job(self):
        wp = WorkerPool(nworkers=1)

        wp.submit(job_no_ctx, 10, 10)

        futs = wp.wait()
        self.assertEqual(len(futs), 1)
        for fut in futs:
            self.assertEqual(fut.result(), job_no_ctx(10, 10))
Пример #3
0
    def test_process_futures(self):
        wp = WorkerPool(nworkers=1)

        wp.submit(job_no_ctx, 10, 10, True)

        futs = wp.wait()

        with self.assertRaises(Exception):
            process_futures(futs, wp)
Пример #4
0
    def test_single_job_with_ctx(self):
        ctx = Context(1)
        ctxs = [ctx]
        wp = WorkerPool(nworkers=1, pool_ctxs=ctxs)

        wp.submit(job_with_ctx, 10, 10)
        futs = wp.wait()
        self.assertEqual(len(futs), 1)
        for fut in futs:
            self.assertEqual(fut.result(), job_with_ctx(ctxs[0], 10, 10))
Пример #5
0
    def test_multiple_jobs_with_less_workers(self):
        njobs = 10

        wp = WorkerPool(nworkers=5)
        for i in range(njobs):
            wp.submit(job_no_ctx, 10 * i, 10 * i)

        futs = wp.wait()
        self.assertEqual(len(futs), njobs)
        for i in range(njobs):
            self.assertEqual(futs[i].result(), job_no_ctx(10 * i, 10 * i))
Пример #6
0
    def test_single_job_with_exception_and_failed_retry(self):
        global nexc
        nexc = 0

        wp = WorkerPool(nworkers=1, retry=1)

        wp.submit(job_no_ctx, 10, 10, True)

        futs = wp.wait()
        self.assertEqual(len(futs), 1)
        for fut in futs:
            self.assertRaises(Exception, fut.result)