Beispiel #1
0
 def test_wrap_future_cancel(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(f1.cancelled())
     self.assertTrue(f2.cancelled())
 def test_wrap_future_cancel(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(f1.cancelled())
     self.assertTrue(f2.cancelled())
 def test_wrap_future_use_global_loop(self, m_events):
     def run(arg):
         return (arg, get_thread_ident())
     ex = concurrent.futures.ThreadPoolExecutor(1)
     f1 = ex.submit(run, 'oi')
     f2 = asyncio.wrap_future(f1)
     self.assertIs(m_events.get_event_loop.return_value, f2._loop)
Beispiel #4
0
    def test_wrap_future_use_global_loop(self, m_events):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, 'oi')
        f2 = asyncio.wrap_future(f1)
        self.assertIs(m_events.get_event_loop.return_value, f2._loop)
Beispiel #5
0
 def test_wrap_future_cancel2(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f1.set_result(42)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertFalse(f1.cancelled())
     self.assertEqual(f1.result(), 42)
     self.assertTrue(f2.cancelled())
 def test_wrap_future_cancel2(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f1.set_result(42)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertFalse(f1.cancelled())
     self.assertEqual(f1.result(), 42)
     self.assertTrue(f2.cancelled())
Beispiel #7
0
    def test_wrap_future(self):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, 'oi')
        f2 = asyncio.wrap_future(f1, loop=self.loop)
        res, ident = self.loop.run_until_complete(f2)
        self.assertIsInstance(f2, asyncio.Future)
        self.assertEqual(res, 'oi')
        self.assertNotEqual(ident, get_thread_ident())
    def test_wrap_future(self):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, "oi")
        f2 = asyncio.wrap_future(f1, loop=self.loop)
        res, ident = self.loop.run_until_complete(f2)
        self.assertIsInstance(f2, asyncio.Future)
        self.assertEqual(res, "oi")
        self.assertNotEqual(ident, get_thread_ident())
Beispiel #9
0
 def test_wrap_future_future(self):
     f1 = asyncio.Future(loop=self.loop)
     f2 = asyncio.wrap_future(f1)
     self.assertIs(f1, f2)
Beispiel #10
0
 def test_wrap_future_future(self):
     f1 = asyncio.Future(loop=self.loop)
     f2 = asyncio.wrap_future(f1)
     self.assertIs(f1, f2)
Beispiel #11
0
 def test_wrap_future(self):
     fut = asyncio.Future()
     self.assertIs(trollius.wrap_future(fut), fut)