1 |
commit: 87aeab1a62cc6fa1d48354a42ec4fa787dbe9603 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun May 6 01:19:08 2018 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun May 6 01:26:50 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=87aeab1a |
7 |
|
8 |
WriterPipeClosedTestCase: retry filling pipe |
9 |
|
10 |
This should suppress spurious writer callback observed |
11 |
twice for pypy in travis. |
12 |
|
13 |
See: https://travis-ci.org/gentoo/portage/jobs/375411936 |
14 |
See: https://travis-ci.org/gentoo/portage/jobs/373734825 |
15 |
|
16 |
.../tests/util/futures/asyncio/test_pipe_closed.py | 39 +++++++++++++--------- |
17 |
1 file changed, 23 insertions(+), 16 deletions(-) |
18 |
|
19 |
diff --git a/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py b/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py |
20 |
index 5398ca35c..e63829888 100644 |
21 |
--- a/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py |
22 |
+++ b/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py |
23 |
@@ -105,25 +105,32 @@ class WriterPipeClosedTestCase(_PipeClosedTestCase, TestCase): |
24 |
|
25 |
writer_callback.called = loop.create_future() |
26 |
_set_nonblocking(write_end.fileno()) |
27 |
+ loop.add_writer(write_end.fileno(), writer_callback) |
28 |
|
29 |
- # Fill up the pipe, so that no writer callbacks should be |
30 |
- # received until the state has changed. |
31 |
- while True: |
32 |
- try: |
33 |
- os.write(write_end.fileno(), 512 * b'0') |
34 |
- except EnvironmentError as e: |
35 |
- if e.errno != errno.EAGAIN: |
36 |
- raise |
37 |
+ # With pypy we've seen intermittent spurious writer callbacks |
38 |
+ # here, so retry until the correct state is achieved. |
39 |
+ tries = 10 |
40 |
+ while tries: |
41 |
+ tries -= 1 |
42 |
+ |
43 |
+ # Fill up the pipe, so that no writer callbacks should be |
44 |
+ # received until the state has changed. |
45 |
+ while True: |
46 |
+ try: |
47 |
+ os.write(write_end.fileno(), 512 * b'0') |
48 |
+ except EnvironmentError as e: |
49 |
+ if e.errno != errno.EAGAIN: |
50 |
+ raise |
51 |
+ break |
52 |
+ |
53 |
+ # Allow the loop to check for IO events, and assert |
54 |
+ # that our future is still not done. |
55 |
+ loop.run_until_complete(asyncio.sleep(0, loop=loop)) |
56 |
+ if writer_callback.called.done(): |
57 |
+ writer_callback.called = loop.create_future() |
58 |
+ else: |
59 |
break |
60 |
|
61 |
- # We've seen at least one spurious writer callback when |
62 |
- # this was registered before the pipe was filled, so |
63 |
- # register it afterwards. |
64 |
- loop.add_writer(write_end.fileno(), writer_callback) |
65 |
- |
66 |
- # Allow the loop to check for IO events, and assert |
67 |
- # that our future is still not done. |
68 |
- loop.run_until_complete(asyncio.sleep(0, loop=loop)) |
69 |
self.assertFalse(writer_callback.called.done()) |
70 |
|
71 |
# Demonstrate that the callback is called afer the |