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.
This commit is contained in:
Aaron Gable 2024-06-12 15:26:30 -07:00 committed by GitHub
parent 2b5b6239a4
commit 80df797486
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 10 deletions

View File

@ -132,7 +132,7 @@ func TestNew(t *testing.T) {
{ {
Name: "unreachable directory URL", Name: "unreachable directory URL",
DirectoryURL: "http://localhost:1987", 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", Name: "wrong directory HTTP status code",
@ -179,7 +179,7 @@ func TestNew(t *testing.T) {
if err == nil && tc.ExpectedError != "" { if err == nil && tc.ExpectedError != "" {
t.Errorf("expected error %q got nil", tc.ExpectedError) t.Errorf("expected error %q got nil", tc.ExpectedError)
} else if err != nil { } else if err != nil {
test.AssertEquals(t, err.Error(), tc.ExpectedError) test.AssertContains(t, err.Error(), tc.ExpectedError)
} }
}) })
} }

View File

@ -992,7 +992,7 @@ func TestFetchHTTP(t *testing.T) {
Host: "ipv6.localhost", Host: "ipv6.localhost",
Path: "/ok", Path: "/ok",
ExpectedProblem: probs.Connection( ExpectedProblem: probs.Connection(
"::1: Fetching http://ipv6.localhost/ok: Error getting validation data"), "::1: Fetching http://ipv6.localhost/ok: Connection refused"),
ExpectedRecords: []core.ValidationRecord{ ExpectedRecords: []core.ValidationRecord{
{ {
Hostname: "ipv6.localhost", Hostname: "ipv6.localhost",
@ -1098,14 +1098,14 @@ func TestFetchHTTP(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500) ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
defer cancel() defer cancel()
body, records, err := va.fetchHTTP(ctx, tc.Host, tc.Path) body, records, err := va.fetchHTTP(ctx, tc.Host, tc.Path)
if err != nil && tc.ExpectedProblem == nil { if tc.ExpectedProblem == nil {
t.Errorf("expected nil prob, got %#v\n", err) test.AssertNotError(t, err, "expected nil prob")
} else if err == nil && tc.ExpectedProblem != nil { } else {
t.Errorf("expected %#v prob, got nil", tc.ExpectedProblem) test.AssertError(t, err, "expected non-nil prob")
} else if err != nil && tc.ExpectedProblem != nil {
prob := detailedError(err) prob := detailedError(err)
test.AssertMarshaledEquals(t, prob, tc.ExpectedProblem) test.AssertMarshaledEquals(t, prob, tc.ExpectedProblem)
} else { }
if tc.ExpectedBody != "" {
test.AssertEquals(t, string(body), tc.ExpectedBody) test.AssertEquals(t, string(body), tc.ExpectedBody)
} }
// in all cases we expect validation records to be present and matching expected // 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 var err error
for range 20 { for range 20 {
_, err = va.validateHTTP01(ctx, dnsi("unroutable.invalid"), expectedToken, expectedKeyAuthorization) _, 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 continue
} else { } else {
break break