summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-03-16 14:21:56 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-03-16 14:21:56 +0100
commitddd02e390644a7ecf9a8d5a4b451cc19724dcd77 (patch)
treed001b753e3f2b65ba503926c21096033b3580754 /tests
parent0eaaa74e51408458a162bf5d2d7813056365268e (diff)
downloadpython-linuxnamespaces-ddd02e390644a7ecf9a8d5a4b451cc19724dcd77.tar.gz
add an asyncio variant of run_in_fork
Diffstat (limited to 'tests')
-rw-r--r--tests/test_simple.py39
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):