diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_simple.py | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/tests/test_simple.py b/tests/test_simple.py index 63f7804..e3d0fd9 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -48,18 +48,33 @@ class IDAllocationTest(unittest.TestCase): self.assertIn(alloc.allocate(3), (1, 2)) -class EventFDTest(unittest.IsolatedAsyncioTestCase): - async def test_async(self) -> None: - efd = linuxnamespaces.EventFD(1, linuxnamespaces.EventFDFlags.NONBLOCK) - fut = asyncio.ensure_future(efd.aread()) - await asyncio.sleep(0.000001) # Let the loop run - self.assertTrue(fut.done()) - self.assertEqual(await fut, 1) - fut = asyncio.ensure_future(efd.aread()) - await asyncio.sleep(0.000001) # Let the loop run - self.assertFalse(fut.done()) - efd.write() - self.assertEqual(await fut, 1) +class AsnycioTest(unittest.IsolatedAsyncioTestCase): + async def test_eventfd(self) -> None: + with linuxnamespaces.EventFD( + 1, linuxnamespaces.EventFDFlags.NONBLOCK + ) as efd: + fut = asyncio.ensure_future(efd.aread()) + await asyncio.sleep(0.000001) # Let the loop run + self.assertTrue(fut.done()) + self.assertEqual(await fut, 1) + fut = asyncio.ensure_future(efd.aread()) + await asyncio.sleep(0.000001) # Let the loop run + self.assertFalse(fut.done()) + efd.write() + self.assertEqual(await fut, 1) + + async def test_run_in_fork(self) -> None: + with linuxnamespaces.EventFD( + 0, linuxnamespaces.EventFDFlags.NONBLOCK + ) as efd: + fut = asyncio.ensure_future(efd.aread()) + @linuxnamespaces.async_run_in_fork + def set_ready(): + efd.write() + await asyncio.sleep(0.000001) # Let the loop run + self.assertFalse(fut.done()) + await set_ready() + await asyncio.wait_for(fut, 10) class UnshareTest(unittest.TestCase): |