Exemplo n.º 1
0
    def test_wait_for_handle(self):
        event = _overlapped.CreateEvent(None, True, False, None)
        self.addCleanup(_winapi.CloseHandle, event)

        # Wait for unset event with 0.2s timeout;
        # result should be False at timeout
        f = self.loop._proactor.wait_for_handle(event, 0.2)
        start = self.loop.time()
        self.loop.run_until_complete(f)
        elapsed = self.loop.time() - start
        self.assertFalse(f.result())
        self.assertTrue(0.18 < elapsed < 0.9, elapsed)

        _overlapped.SetEvent(event)

        # Wait for for set event;
        # result should be True immediately
        f = self.loop._proactor.wait_for_handle(event, 10)
        start = self.loop.time()
        self.loop.run_until_complete(f)
        elapsed = self.loop.time() - start
        self.assertTrue(f.result())
        self.assertTrue(0 <= elapsed < 0.1, elapsed)

        _overlapped.ResetEvent(event)

        # Wait for unset event with a cancelled future;
        # CancelledError should be raised immediately
        f = self.loop._proactor.wait_for_handle(event, 10)
        f.cancel()
        start = self.loop.time()
        with self.assertRaises(asyncio.CancelledError):
            self.loop.run_until_complete(f)
        elapsed = self.loop.time() - start
        self.assertTrue(0 <= elapsed < 0.1, elapsed)
Exemplo n.º 2
0
    def test_wait_for_handle(self):
        event = _overlapped.CreateEvent(None, True, False, None)
        self.addCleanup(_winapi.CloseHandle, event)

        # Wait for unset event with 0.5s timeout;
        # result should be False at timeout
        fut = self.loop._proactor.wait_for_handle(event, 0.5)
        start = self.loop.time()
        done = self.loop.run_until_complete(fut)
        elapsed = self.loop.time() - start

        self.assertEqual(done, False)
        self.assertFalse(fut.result())
        # bpo-31008: Tolerate only 450 ms (at least 500 ms expected),
        # because of bad clock resolution on Windows
        self.assertTrue(0.45 <= elapsed <= 0.9, elapsed)

        _overlapped.SetEvent(event)

        # Wait for set event;
        # result should be True immediately
        fut = self.loop._proactor.wait_for_handle(event, 10)
        start = self.loop.time()
        done = self.loop.run_until_complete(fut)
        elapsed = self.loop.time() - start

        self.assertEqual(done, True)
        self.assertTrue(fut.result())
        self.assertTrue(0 <= elapsed < 0.3, elapsed)

        # asyncio issue #195: cancelling a done _WaitHandleFuture
        # must not crash
        fut.cancel()
Exemplo n.º 3
0
    def test_wait_for_handle(self):
        event = _overlapped.CreateEvent(None, True, False, None)
        self.addCleanup(_winapi.CloseHandle, event)

        # Wait for unset event with 0.5s timeout;
        # result should be False at timeout
        fut = self.loop._proactor.wait_for_handle(event, 0.5)
        start = self.loop.time()
        done = self.loop.run_until_complete(fut)
        elapsed = self.loop.time() - start

        self.assertEqual(done, False)
        self.assertFalse(fut.result())
        self.assertTrue(0.48 < elapsed < 0.9, elapsed)

        _overlapped.SetEvent(event)

        # Wait for set event;
        # result should be True immediately
        fut = self.loop._proactor.wait_for_handle(event, 10)
        start = self.loop.time()
        done = self.loop.run_until_complete(fut)
        elapsed = self.loop.time() - start

        self.assertEqual(done, True)
        self.assertTrue(fut.result())
        self.assertTrue(0 <= elapsed < 0.3, elapsed)

        # asyncio issue #195: cancelling a done _WaitHandleFuture
        # must not crash
        fut.cancel()
 def test_wait_for_handle(self):
     event = _overlapped.CreateEvent(None, True, False, None)
     self.addCleanup(_winapi.CloseHandle, event)
     fut = self.loop._proactor.wait_for_handle(event, 0.5)
     start = self.loop.time()
     done = self.loop.run_until_complete(fut)
     elapsed = self.loop.time() - start
     self.assertEqual(done, False)
     self.assertFalse(fut.result())
     self.assertTrue(0.48 < elapsed < 0.9, elapsed)
     _overlapped.SetEvent(event)
     fut = self.loop._proactor.wait_for_handle(event, 10)
     start = self.loop.time()
     done = self.loop.run_until_complete(fut)
     elapsed = self.loop.time() - start
     self.assertEqual(done, True)
     self.assertTrue(fut.result())
     self.assertTrue(0 <= elapsed < 0.3, elapsed)
     fut.cancel()