commit:     87aeab1a62cc6fa1d48354a42ec4fa787dbe9603
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May  6 01:19:08 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May  6 01:26:50 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=87aeab1a

WriterPipeClosedTestCase: retry filling pipe

This should suppress spurious writer callback observed
twice for pypy in travis.

See: https://travis-ci.org/gentoo/portage/jobs/375411936
See: https://travis-ci.org/gentoo/portage/jobs/373734825

 .../tests/util/futures/asyncio/test_pipe_closed.py | 39 +++++++++++++---------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py 
b/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py
index 5398ca35c..e63829888 100644
--- a/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py
+++ b/pym/portage/tests/util/futures/asyncio/test_pipe_closed.py
@@ -105,25 +105,32 @@ class WriterPipeClosedTestCase(_PipeClosedTestCase, 
TestCase):
 
                        writer_callback.called = loop.create_future()
                        _set_nonblocking(write_end.fileno())
+                       loop.add_writer(write_end.fileno(), writer_callback)
 
-                       # Fill up the pipe, so that no writer callbacks should 
be
-                       # received until the state has changed.
-                       while True:
-                               try:
-                                       os.write(write_end.fileno(), 512 * b'0')
-                               except EnvironmentError as e:
-                                       if e.errno != errno.EAGAIN:
-                                               raise
+                       # With pypy we've seen intermittent spurious writer 
callbacks
+                       # here, so retry until the correct state is achieved.
+                       tries = 10
+                       while tries:
+                               tries -= 1
+
+                               # Fill up the pipe, so that no writer callbacks 
should be
+                               # received until the state has changed.
+                               while True:
+                                       try:
+                                               os.write(write_end.fileno(), 
512 * b'0')
+                                       except EnvironmentError as e:
+                                               if e.errno != errno.EAGAIN:
+                                                       raise
+                                               break
+
+                               # Allow the loop to check for IO events, and 
assert
+                               # that our future is still not done.
+                               loop.run_until_complete(asyncio.sleep(0, 
loop=loop))
+                               if writer_callback.called.done():
+                                       writer_callback.called = 
loop.create_future()
+                               else:
                                        break
 
-                       # We've seen at least one spurious writer callback when
-                       # this was registered before the pipe was filled, so
-                       # register it afterwards.
-                       loop.add_writer(write_end.fileno(), writer_callback)
-
-                       # Allow the loop to check for IO events, and assert
-                       # that our future is still not done.
-                       loop.run_until_complete(asyncio.sleep(0, loop=loop))
                        self.assertFalse(writer_callback.called.done())
 
                        # Demonstrate that the callback is called afer the

Reply via email to