From 8931a36cb3dcf250a992443a73ad1ab302a7f40e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 30 Sep 2021 00:25:05 +0200 Subject: [PATCH] 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. --- internal/netxlite/integration_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/netxlite/integration_test.go b/internal/netxlite/integration_test.go index d4c0234..8cab1a3 100644 --- a/internal/netxlite/integration_test.go +++ b/internal/netxlite/integration_test.go @@ -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 {