Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | """This test checks for correct wait3() behavior. |
| 2 | """ |
| 3 | |
| 4 | import os |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 5 | import time |
Benjamin Peterson | e549ead | 2009-03-28 21:42:05 +0000 | [diff] [blame] | 6 | import unittest |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 7 | from test.fork_wait import ForkWait |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 8 | from test.support import reap_children |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 9 | |
Brett Cannon | cc13431 | 2012-11-14 15:49:55 -0500 | [diff] [blame] | 10 | if not hasattr(os, 'fork'): |
Brett Cannon | cd8efa3 | 2012-11-14 15:16:53 -0500 | [diff] [blame] | 11 | raise unittest.SkipTest("os.fork not defined") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 12 | |
Brett Cannon | cd8efa3 | 2012-11-14 15:16:53 -0500 | [diff] [blame] | 13 | if not hasattr(os, 'wait3'): |
| 14 | raise unittest.SkipTest("os.wait3 not defined") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 15 | |
| 16 | class Wait3Test(ForkWait): |
| 17 | def wait_impl(self, cpid): |
Antoine Pitrou | 606c3f5 | 2011-05-09 21:17:02 +0200 | [diff] [blame] | 18 | # This many iterations can be required, since some previously run |
| 19 | # tests (e.g. test_ctypes) could have spawned a lot of children |
| 20 | # very quickly. |
Victor Stinner | 1e48eb3 | 2014-03-18 00:39:04 +0100 | [diff] [blame] | 21 | deadline = time.monotonic() + 10.0 |
| 22 | while time.monotonic() <= deadline: |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 23 | # wait3() shouldn't hang, but some of the buildbots seem to hang |
| 24 | # in the forking tests. This is an attempt to fix the problem. |
| 25 | spid, status, rusage = os.wait3(os.WNOHANG) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 26 | if spid == cpid: |
| 27 | break |
Antoine Pitrou | 606c3f5 | 2011-05-09 21:17:02 +0200 | [diff] [blame] | 28 | time.sleep(0.1) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 29 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 30 | self.assertEqual(spid, cpid) |
| 31 | self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
| 32 | self.assertTrue(rusage) |
| 33 | |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 34 | def tearDownModule(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 35 | reap_children() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 36 | |
| 37 | if __name__ == "__main__": |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 38 | unittest.main() |