Пример #1
0
    def test_managed(self):
        with self.executor() as ex:
            a = ex.future(work_load, -1)
            self.assertTrue(is_promise(a))

            # generate some minor workload, enough to engage a queue
            values = [ex.future(work_load, x) for x in xrange(0, 999)]

            b = ex.future(work_load, -101)
            self.assertFalse(is_delivered(b))

        # the managed interface implicitly calls the deliver() method
        # on the executor, so by the time we get here, everything
        # should be delivered.

        self.assertTrue(is_promise(a))
        self.assertTrue(is_delivered(a))
        self.assertEqual(deliver(a), 0)

        self.assertTrue(is_promise(b))
        self.assertTrue(is_delivered(b))
        self.assertEqual(deliver(b), -100)

        self.assertEqual([deliver(v) for v in values],
                         list(xrange(1, 1000)))
Пример #2
0
    def test_terminate(self):
        ex = self.executor()

        # generate some minor workload, enough to engage a queue
        values = [ex.future(work_load, x) for x in xrange(0, 999)]

        b = ex.future(work_load, -101)
        self.assertFalse(is_delivered(b))

        ex.terminate()
        self.assertFalse(is_delivered(b))
Пример #3
0
    def test_blocking(self):
        ex = self.executor()

        # generate some minor workload, enough to engage a queue
        values = [ex.future(work_load, x) for x in xrange(0, 999)]

        b = ex.future(work_load, -101)
        self.assertFalse(is_delivered(b))
        self.assertEqual(deliver(b), -100)

        ex.deliver()
Пример #4
0
    def test_raises(self):
        ex = self.executor()

        # generate some minor workload, enough to engage a queue
        values = [ex.future(work_load, x) for x in xrange(0, 999)]

        b = ex.future(fail_load, -101)

        self.assertFalse(is_delivered(b))
        self.assertRaises(TacoException, lambda: deliver(b))

        ex.terminate()