Esempio n. 1
0
 def test_gather_shield(self):
     child1 = futures.Future(loop=self.loop)
     child2 = futures.Future(loop=self.loop)
     inner1 = tasks.shield(child1, loop=self.loop)
     inner2 = tasks.shield(child2, loop=self.loop)
     parent = tasks.gather(inner1, inner2, loop=self.loop)
     test_utils.run_briefly(self.loop)
     parent.cancel()
     # This should cancel inner1 and inner2 but bot child1 and child2.
     test_utils.run_briefly(self.loop)
     self.assertIsInstance(parent.exception(), futures.CancelledError)
     self.assertTrue(inner1.cancelled())
     self.assertTrue(inner2.cancelled())
     child1.set_result(1)
     child2.set_result(2)
     test_utils.run_briefly(self.loop)
Esempio n. 2
0
 def test_shield_cancel(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     test_utils.run_briefly(self.loop)
     inner.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(outer.cancelled())
Esempio n. 3
0
 def test_shield_cancel(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     test_utils.run_briefly(self.loop)
     inner.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(outer.cancelled())
Esempio n. 4
0
 def test_gather_shield(self):
     child1 = futures.Future(loop=self.loop)
     child2 = futures.Future(loop=self.loop)
     inner1 = tasks.shield(child1, loop=self.loop)
     inner2 = tasks.shield(child2, loop=self.loop)
     parent = tasks.gather(inner1, inner2, loop=self.loop)
     test_utils.run_briefly(self.loop)
     parent.cancel()
     # This should cancel inner1 and inner2 but bot child1 and child2.
     test_utils.run_briefly(self.loop)
     self.assertIsInstance(parent.exception(), futures.CancelledError)
     self.assertTrue(inner1.cancelled())
     self.assertTrue(inner2.cancelled())
     child1.set_result(1)
     child2.set_result(2)
     test_utils.run_briefly(self.loop)
Esempio n. 5
0
 def test_shield_exception(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     test_utils.run_briefly(self.loop)
     exc = RuntimeError('expected')
     inner.set_exception(exc)
     test_utils.run_briefly(self.loop)
     self.assertIs(outer.exception(), exc)
Esempio n. 6
0
 def test_shield_exception(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     test_utils.run_briefly(self.loop)
     exc = RuntimeError('expected')
     inner.set_exception(exc)
     test_utils.run_briefly(self.loop)
     self.assertIs(outer.exception(), exc)
Esempio n. 7
0
 def test_shield_gather(self):
     child1 = futures.Future(loop=self.loop)
     child2 = futures.Future(loop=self.loop)
     parent = tasks.gather(child1, child2, loop=self.loop)
     outer = tasks.shield(parent, loop=self.loop)
     test_utils.run_briefly(self.loop)
     outer.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(outer.cancelled())
     child1.set_result(1)
     child2.set_result(2)
     test_utils.run_briefly(self.loop)
     self.assertEqual(parent.result(), [1, 2])
Esempio n. 8
0
 def test_shield_gather(self):
     child1 = futures.Future(loop=self.loop)
     child2 = futures.Future(loop=self.loop)
     parent = tasks.gather(child1, child2, loop=self.loop)
     outer = tasks.shield(parent, loop=self.loop)
     test_utils.run_briefly(self.loop)
     outer.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(outer.cancelled())
     child1.set_result(1)
     child2.set_result(2)
     test_utils.run_briefly(self.loop)
     self.assertEqual(parent.result(), [1, 2])
Esempio n. 9
0
 def outer():
     nonlocal proof
     yield from tasks.shield(inner(), loop=self.loop)
     proof += 100
Esempio n. 10
0
 def test_shield_shortcut(self):
     fut = futures.Future(loop=self.loop)
     fut.set_result(42)
     res = self.loop.run_until_complete(tasks.shield(fut))
     self.assertEqual(res, 42)
Esempio n. 11
0
 def test_shield_result(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     inner.set_result(42)
     res = self.loop.run_until_complete(outer)
     self.assertEqual(res, 42)
Esempio n. 12
0
 def outer():
     nonlocal proof
     yield from tasks.shield(inner(), loop=self.loop)
     proof += 100
Esempio n. 13
0
 def test_shield_shortcut(self):
     fut = futures.Future(loop=self.loop)
     fut.set_result(42)
     res = self.loop.run_until_complete(tasks.shield(fut))
     self.assertEqual(res, 42)
Esempio n. 14
0
 def test_shield_result(self):
     inner = futures.Future(loop=self.loop)
     outer = tasks.shield(inner)
     inner.set_result(42)
     res = self.loop.run_until_complete(outer)
     self.assertEqual(res, 42)