(self)
| 5349 | |
| 5350 | @support.requires_resource('walltime') |
| 5351 | def test_wait_integer(self): |
| 5352 | from multiprocessing.connection import wait |
| 5353 | |
| 5354 | expected = 3 |
| 5355 | sorted_ = lambda l: sorted(l, key=lambda x: id(x)) |
| 5356 | sem = multiprocessing.Semaphore(0) |
| 5357 | a, b = multiprocessing.Pipe() |
| 5358 | p = multiprocessing.Process(target=self.signal_and_sleep, |
| 5359 | args=(sem, expected)) |
| 5360 | |
| 5361 | p.start() |
| 5362 | self.assertIsInstance(p.sentinel, int) |
| 5363 | self.assertTrue(sem.acquire(timeout=20)) |
| 5364 | |
| 5365 | start = time.monotonic() |
| 5366 | res = wait([a, p.sentinel, b], expected + 20) |
| 5367 | delta = time.monotonic() - start |
| 5368 | |
| 5369 | self.assertEqual(res, [p.sentinel]) |
| 5370 | self.assertLess(delta, expected + 2) |
| 5371 | self.assertGreater(delta, expected - 2) |
| 5372 | |
| 5373 | a.send(None) |
| 5374 | |
| 5375 | start = time.monotonic() |
| 5376 | res = wait([a, p.sentinel, b], 20) |
| 5377 | delta = time.monotonic() - start |
| 5378 | |
| 5379 | self.assertEqual(sorted_(res), sorted_([p.sentinel, b])) |
| 5380 | self.assertLess(delta, 0.4) |
| 5381 | |
| 5382 | b.send(None) |
| 5383 | |
| 5384 | start = time.monotonic() |
| 5385 | res = wait([a, p.sentinel, b], 20) |
| 5386 | delta = time.monotonic() - start |
| 5387 | |
| 5388 | self.assertEqual(sorted_(res), sorted_([a, p.sentinel, b])) |
| 5389 | self.assertLess(delta, 0.4) |
| 5390 | |
| 5391 | p.terminate() |
| 5392 | p.join() |
| 5393 | |
| 5394 | def test_neg_timeout(self): |
| 5395 | from multiprocessing.connection import wait |
nothing calls this directly
no test coverage detected