fix(netxlite): make test less flaky on macOS (#526)

The explanatory comment in the diff says it all.

Work done while I was converging with https://github.com/ooni/probe/issues/1733.
This commit is contained in:
Simone Basso 2021-09-30 00:25:05 +02:00 committed by GitHub
parent 24a6ac9a5f
commit 8931a36cb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,9 +224,24 @@ func TestMeasureWithDialer(t *testing.T) {
})
t.Run("on timeout", func(t *testing.T) {
// Note: this test was flaky sometimes on macOS. I've seen in
// particular this failure on 2021-09-29:
//
// ```
// --- FAIL: TestMeasureWithDialer (8.25s)
// --- FAIL: TestMeasureWithDialer/on_timeout (8.22s)
// integration_test.go:233: not the error we expected timed_out
// ```
//
// My explanation of this failure is that the ETIMEDOUT from
// the kernel races with the timeout we've configured. For this
// reason, I have set a smaller context timeout (see below).
//
d := netxlite.NewDialerWithoutResolver(log.Log)
defer d.CloseIdleConnections()
ctx := context.Background()
const timeout = 5 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
// Here we assume 8.8.4.4:1 is filtered
conn, err := d.DialContext(ctx, "tcp", "8.8.4.4:1")
if err == nil || err.Error() != netxlite.FailureGenericTimeoutError {