diff --git a/internal/discriminator/routewatchtags_test.go b/internal/discriminator/routewatchtags_test.go index 33327c9..4b3e41b 100644 --- a/internal/discriminator/routewatchtags_test.go +++ b/internal/discriminator/routewatchtags_test.go @@ -153,14 +153,10 @@ func TestUnsetRouteWatchChangesNothing(t *testing.T) { func TestUnreachableRouteWatchLetsTheRequestThroughAndSaysWhy(t *testing.T) { t.Parallel() - // A stand-in that is closed at once, so that the port refuses connections. - dead := httptest.NewServer(http.NotFoundHandler()) - url := dead.URL - - dead.Close() - + // Another test can take a closed server's port at once, so routewatch's + // address here is a multicast address, to which TCP cannot connect. s, _, _ := startWithClock(t, "", map[string]string{ - lookupSource: off, routeWatchURL: url, + lookupSource: off, routeWatchURL: "http://224.0.0.1", }) wantTagsMissing(t, s.get(fromDE, http.StatusOK, requestlog.ActionForward), diff --git a/internal/routewatch/routewatch_test.go b/internal/routewatch/routewatch_test.go index 60c197a..c74b1af 100644 --- a/internal/routewatch/routewatch_test.go +++ b/internal/routewatch/routewatch_test.go @@ -239,12 +239,17 @@ func TestAnswerRoutewatchCannotBeTakenFromFails(t *testing.T) { } } -func TestRefusedConnectionFailsTheQueryAndTheLogOmitsTheClient(t *testing.T) { +func TestUnreachableRoutewatchFailsTheQueryAndTheLogOmitsTheClient(t *testing.T) { t.Parallel() f := newFixture(t, answering(routedAnswer)) - f.server.Close() + // Another test can take a closed server's port at once, so routewatch's + // address here is a multicast address, to which TCP cannot connect. + f.client = routewatch.New(routewatch.Params{ + URL: "http://224.0.0.1/", Now: f.clk.Now, + ProcessLog: slog.New(slog.NewTextHandler(f.log, nil)), + }) f.route() f.waitFor(routewatch.RequestFailed) diff --git a/internal/sww/sww_test.go b/internal/sww/sww_test.go index 8638cfa..3087637 100644 --- a/internal/sww/sww_test.go +++ b/internal/sww/sww_test.go @@ -975,9 +975,20 @@ func TestStalledRemoteLogEndpointHoldsUpNoRequest(t *testing.T) { t.Errorf("no line dropped in the metrics:\n%s", metrics) } - // Closed, the endpoint refuses the connection made to send the - // lines still waiting at the stop, which then does not wait. - _ = endpoint.Close() + // From here the endpoint closes each connection it takes, so the + // one made to send the lines still waiting at the stop fails at + // once. Closing the endpoint instead would free its port for + // another test to take. + go func() { + for { + conn, err := endpoint.Accept() + if err != nil { + return + } + + _ = conn.Close() + } + }() }) out.line(t, "type", "request")