This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_kqueue failure on OS X
Type: Stage:
Components: Tests Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: christian.heimes, exarkun, mark.dickinson
Priority: normal Keywords: patch

Created on 2009-01-21 17:58 by mark.dickinson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue5025.patch mark.dickinson, 2009-01-21 19:15
Messages (5)
msg80335 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-01-21 17:58
I just got a one-off, non-reproducible test_kqueue failure, during a 'make 
test' of the trunk, on OS X 10.5.6.  Here's the output:

test_kqueue
test test_kqueue failed -- Traceback (most recent call last):
  File "/Users/dickinsm/python_source/trunk/Lib/test/test_kqueue.py", line 
136, in test_queue_event
    (server.fileno(), select.KQ_FILTER_READ, flags)])
AssertionError: [(5L, -2, 5L), (6L, -2, 5L), (6L, -1, 5L)] != [(5, -2, 5), 
(5, -1, 5), (6, -2, 5), (6, -1, 5)]

Looking at the test_queue.py file just before line 136, I see:

        events = kq.control(None, 4, 1)
        # We may need to call it several times
        for i in range(5):
            if len(events) == 4:
                break
            events = kq.control(None, 4, 1)

Would adding a time.sleep(1.0) to the for loop make this test more robust?

My first impression was that the '1' in 'kq.control(None, 4, 1)' already 
did this;  i.e., that it meant that the kq.control function would wait up 
to 1 second for a response, but that doesn't seem to be true.  I tried 
replacing the 1 with 1000000 and the test still runs nearly 
instantaneously, even in the case where the kq.control call doesn't get 4 
events first time around.

Out of curiosity, *why* is there a need to call this several times? I 
fully believe there *is* such a need;  I just don't know what it is.  
Something to do with waiting for the socket send calls to complete, I 
assume?
msg80336 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-01-21 18:04
> My first impression was that the '1' in 'kq.control(None, 4, 1)'
already did this;  i.e., that it meant that the kq.control function
would wait up to 1 second for a response, but that doesn't seem to be true.

Since there are events in the result, the call succeeds immediately. 
The timeout only defines an upper bound on how long control will block
before returning with *no* results.  Since the loop doesn't handle any
of the events, there's always some ready right away after the first call.

> Out of curiosity, *why* is there a need to call this several times?

It's out of the control of the test what the kernel does to deliver the
event notifications.  Since the test is waiting for multiple events, the
loop helps it get them all (although clearly it's not totally reliable).
msg80341 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-01-21 19:15
Here's a patch:

 - add a time.sleep(1.0) in between calls to kq.control
 - restructure for loop slightly: move initial kq.control call inside it 
 - bump number of trials from 5 to 10 (why not?!)
 - produce more meaningful error message in the unlikely event
   that we never get the 4 events we're waiting for
msg80445 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-01-24 12:31
I just saw this same test_kqueue failure pop up on the OS X 3.x buildbot,
so it's evidently not just a peculiarity of my machine.

Unless there are any objections, I'll go ahead and check this in:  I think 
it's a sufficiently trivial fix that it's not worth wasting Christian's 
time with. :)
msg80458 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-01-24 16:18
Fixed in the trunk in r68897.  Will merge to 2.6, 3.0 and 3.1.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49275
2009-01-24 16:18:42mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg80458
2009-01-24 12:33:12mark.dickinsonsetpriority: normal
2009-01-24 12:31:34mark.dickinsonsetassignee: christian.heimes -> mark.dickinson
messages: + msg80445
2009-01-21 19:15:42mark.dickinsonsetfiles: + issue5025.patch
keywords: + patch
messages: + msg80341
2009-01-21 18:04:52exarkunsetnosy: + exarkun
messages: + msg80336
2009-01-21 17:58:18mark.dickinsoncreate