Codebase list golang-golang-x-sys / e075d93
unix: deflake TestPselect and TestSelect on linux On some platforms (namely Linux), Select and Pselect update the passed-in timeval/timespec, which might lead to failing tests in case of an EINTR. Fix this by always resetting the timeval/timespec before calling Select/Pselect. Also change accept timeouts within 2/3 margin of the expected timeout, like already done in TestSelect. While at it, fix the failure log to use the common "got X, expected Y" message. Fixes golang/go#42210 Change-Id: Id0efbbecc9c0bf44c102d5d1880b1bae32980ad1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/265020 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Tobias Klauser authored 3 years ago Tobias Klauser committed 3 years ago
2 changed file(s) with 12 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
233233 }
234234
235235 dur := 2500 * time.Microsecond
236 ts := unix.NsecToTimespec(int64(dur))
237236 var took time.Duration
238237 for {
238 // On some platforms (e.g. Linux), the passed-in timespec is
239 // updated by pselect(2). Make sure to reset to the full
240 // duration in case of an EINTR.
241 ts := unix.NsecToTimespec(int64(dur))
239242 start := time.Now()
240243 n, err := unix.Pselect(0, nil, nil, nil, &ts, nil)
241244 took = time.Since(start)
251254 break
252255 }
253256
254 if took < dur {
255 t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took)
257 // On some builder the actual timeout might also be slightly less than the requested.
258 // Add an acceptable margin to avoid flaky tests.
259 if took < dur*2/3 {
260 t.Errorf("Pselect: got %v timeout, expected at least %v", took, dur)
256261 }
257262 }
258263
536536 }
537537
538538 dur := 250 * time.Millisecond
539 tv := unix.NsecToTimeval(int64(dur))
540539 var took time.Duration
541540 for {
541 // On some platforms (e.g. Linux), the passed-in timeval is
542 // updated by select(2). Make sure to reset to the full duration
543 // in case of an EINTR.
544 tv := unix.NsecToTimeval(int64(dur))
542545 start := time.Now()
543546 n, err := unix.Select(0, nil, nil, nil, &tv)
544547 took = time.Since(start)