From 80df7974863866c58cb8a562a1131f1dbe2e4496 Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Wed, 12 Jun 2024 15:26:30 -0700 Subject: [PATCH] Fix flaky unittest failures (#7544) Fix three unit tests which have been flakily failing for the last several weeks: //test/load-generator/acme: TestNew/unreachable_directory_URL Fixed by changing the error checking code to care only about the underlying "connection refused" message, and not the IP address from which it was receieved. //va: TestHTTPDialTimeout Fixed by correcting the error checking code to look for "network is unreachable" instead of "Network unreachable" //va: TestFetchHTTP/Broken_IPv6_only Fixed by making the expected error message more specific -- it was previously looking for "Error getting validation data", which is the message that `detailedError` gives for errors it doesn't recognize. An underlying library has changed to provide an error type that `detailedError` now recognizes as a connection error. --- test/load-generator/acme/directory_test.go | 4 ++-- va/http_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/load-generator/acme/directory_test.go b/test/load-generator/acme/directory_test.go index 0c1fa55cd..3ee286a10 100644 --- a/test/load-generator/acme/directory_test.go +++ b/test/load-generator/acme/directory_test.go @@ -132,7 +132,7 @@ func TestNew(t *testing.T) { { Name: "unreachable directory URL", DirectoryURL: "http://localhost:1987", - ExpectedError: "Get \"http://localhost:1987\": dial tcp 127.0.0.1:1987: connect: connection refused", + ExpectedError: "connect: connection refused", }, { Name: "wrong directory HTTP status code", @@ -179,7 +179,7 @@ func TestNew(t *testing.T) { if err == nil && tc.ExpectedError != "" { t.Errorf("expected error %q got nil", tc.ExpectedError) } else if err != nil { - test.AssertEquals(t, err.Error(), tc.ExpectedError) + test.AssertContains(t, err.Error(), tc.ExpectedError) } }) } diff --git a/va/http_test.go b/va/http_test.go index 969171a11..038803539 100644 --- a/va/http_test.go +++ b/va/http_test.go @@ -992,7 +992,7 @@ func TestFetchHTTP(t *testing.T) { Host: "ipv6.localhost", Path: "/ok", ExpectedProblem: probs.Connection( - "::1: Fetching http://ipv6.localhost/ok: Error getting validation data"), + "::1: Fetching http://ipv6.localhost/ok: Connection refused"), ExpectedRecords: []core.ValidationRecord{ { Hostname: "ipv6.localhost", @@ -1098,14 +1098,14 @@ func TestFetchHTTP(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500) defer cancel() body, records, err := va.fetchHTTP(ctx, tc.Host, tc.Path) - if err != nil && tc.ExpectedProblem == nil { - t.Errorf("expected nil prob, got %#v\n", err) - } else if err == nil && tc.ExpectedProblem != nil { - t.Errorf("expected %#v prob, got nil", tc.ExpectedProblem) - } else if err != nil && tc.ExpectedProblem != nil { + if tc.ExpectedProblem == nil { + test.AssertNotError(t, err, "expected nil prob") + } else { + test.AssertError(t, err, "expected non-nil prob") prob := detailedError(err) test.AssertMarshaledEquals(t, prob, tc.ExpectedProblem) - } else { + } + if tc.ExpectedBody != "" { test.AssertEquals(t, string(body), tc.ExpectedBody) } // in all cases we expect validation records to be present and matching expected @@ -1378,7 +1378,7 @@ func TestHTTPDialTimeout(t *testing.T) { var err error for range 20 { _, err = va.validateHTTP01(ctx, dnsi("unroutable.invalid"), expectedToken, expectedKeyAuthorization) - if err != nil && strings.Contains(err.Error(), "Network unreachable") { + if err != nil && strings.Contains(err.Error(), "network is unreachable") { continue } else { break