示例#1
0
 def test_set_exception(self):
     f = Future(self.task)
     e = ValueError("test Error")
     f.set_exception(e)
     self.assertTrue(f.done())
     self.assertRaises(ValueError, f.result, 0)
     self.assertEqual(f.exception(), e)
示例#2
0
 def test_set_exception(self):
     f = Future(self.task)
     e = ValueError("test Error")
     f.set_exception(e)
     self.assertTrue(f.done())
     self.assertRaises(ValueError, f.result, 0)
     self.assertEqual(f.exception(), e)
示例#3
0
 def test_set_exception(self):
     f = Future(self.context)
     e = ValueError("test Error")
     f.set_exception(e)
     assert f.done()
     with self.assertRaises(ValueError):
         f.result(timeout=0)
     assert f.exception() == e
示例#4
0
    def test_wait_all(self):
        t = Task("testTask", self.proc)
        f1 = Future(t)
        f2 = Future(t)
        f3 = Future(t)
        f0 = Future(t)
        t._futures = {0: f0, 1: f1, 2: f2, 3: f3}
        f_wait1 = [f2, f0]
        self.assertRaises(queue.Empty, t.wait_all, f_wait1, 0)

        resp0 = Return(0, None, None)
        resp0.set_value('testVal')
        resp2 = Error(2, None, None)
        t.q.put(resp0)
        t.q.put(resp2)
        t.wait_all( f_wait1, 0)
        self.assertEqual(t._futures, {1: f1, 3: f3})
        self.assertEqual(f0.done(), True)
        self.assertEqual(f1.done(), False)
        self.assertEqual(f2.done(), True)
        self.assertEqual(f3.done(), False)
        self.assertEqual(self.proc.q.qsize(), 0)

        resp3 = Delta(3, None, None)
        t.q.put(resp3)
        f_wait1 = [f3]
        self.assertRaises(ValueError, t.wait_all, f_wait1, 0.01)
        t.stop()
        self.assertRaises(RuntimeWarning, t.wait_all, f_wait1, 0.01)

        resp1 = Return(1, None, None)
        resp1.set_value('testVal')
        t.q.put(resp1)
        self.assertRaises(queue.Empty, t.wait_all, f_wait1, 0.01)
        self.assertEqual(t._futures, {})

        t._futures = {0: f0, 1: f1, 2: f2}
        t.q.put(resp1)
        t.q.put(Task.TASK_STOP)
        self.assertEqual(f1.result(), 'testVal')
    def test_wait_all(self):
        t = Task("testTask", self.proc)
        f1 = Future(t)
        f2 = Future(t)
        f3 = Future(t)
        f0 = Future(t)
        t._futures = {0: f0, 1: f1, 2: f2, 3: f3}
        f_wait1 = [f2, f0]
        self.assertRaises(queue.Empty, t.wait_all, f_wait1, 0)

        resp0 = Return(0, None, None)
        resp0.set_value('testVal')
        resp2 = Error(2, None, None)
        t.q.put(resp0)
        t.q.put(resp2)
        self.assertRaises(ValueError, t.wait_all, f_wait1, 0)
        self.assertEqual(t._futures, {1: f1, 3: f3})
        self.assertEqual(f0.done(), True)
        self.assertEqual(f1.done(), False)
        self.assertEqual(f2.done(), True)
        self.assertEqual(f3.done(), False)
        self.assertEqual(self.proc.q.qsize(), 0)

        resp3 = Delta(3, None, None)
        t.q.put(resp3)
        f_wait1 = [f3]
        self.assertRaises(ValueError, t.wait_all, f_wait1, 0.01)
        t.stop()
        self.assertRaises(StopIteration, t.wait_all, f_wait1, 0.01)

        resp1 = Return(1, None, None)
        resp1.set_value('testVal')
        t.q.put(resp1)
        self.assertRaises(queue.Empty, t.wait_all, f_wait1, 0.01)
        self.assertEqual(t._futures, {})

        t._futures = {0: f0, 1: f1, 2: f2}
        t.q.put(resp1)
        t.q.put(Spawnable.STOP)
        self.assertEqual(f1.result(), 'testVal')
示例#6
0
 def test_set_exception(self):
     f = Future(self.task)
     f.set_exception("test Error")
     self.assertTrue(f.done())
     self.assertRaises(RemoteError, f.result, 0)
     self.assertEqual(f.exception(),'test Error')
示例#7
0
 def test_set_result(self):
     f = Future(self.task)
     f.set_result("testResult")
     self.assertTrue(f.done())
     self.assertEqual(f.result(0), "testResult")
示例#8
0
 def test_set_exception(self):
     f = Future(self.task)
     f.set_exception("test Error")
     self.assertTrue(f.done())
     self.assertRaises(RemoteError, f.result, 0)
     self.assertEqual(f.exception(), 'test Error')
示例#9
0
 def test_set_result(self):
     f = Future(self.task)
     f.set_result("testResult")
     self.assertTrue(f.done())
     self.assertEqual(f.result(0), "testResult")
示例#10
0
 def test_set_result(self):
     f = Future(self.context)
     f.set_result("testResult")
     assert f.done()
     assert f.result(0) == "testResult"