Skip to content

Commit

Permalink
httptransport: fix test flake
Browse files Browse the repository at this point in the history
Saw this test flake in CI and managed to reproduce locally.
I haven't been able to reproduce with this patch, but don't have a great
explanation as to why it's not consistent.

Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Apr 9, 2024
1 parent bf7005f commit 31db514
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions httptransport/instrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,26 @@ clair_http_test_request_total{code="500",handler="err",method="get"} 1

srv := httptest.NewUnstartedServer(m)
srv.Config.BaseContext = func(_ net.Listener) context.Context { return ctx }
srv.Start()
defer srv.Close()

c := srv.Client()
for _, p := range []string{"ok", "err", "err?panic=1"} {
u := srv.URL + "/" + p
t.Logf("making request: %q", u)
res, err := c.Get(u)
if err != nil {
t.Error(err)
// Create a scope for do the actual requests.
//
// Doing this and having the server teardown run synchronously should be
// enough time to ensure the metrics are actually collected.
func() {
srv.Start()
defer srv.Close()

c := srv.Client()
for _, p := range []string{"ok", "err", "err?panic=1"} {
u := srv.URL + "/" + p
t.Logf("making request: %q", u)
res, err := c.Get(u)
if err != nil {
t.Error(err)
}
t.Logf("got status: %q", res.Status)
}
t.Logf("got status: %q", res.Status)
}
}()

if err := testutil.GatherAndCompare(reg, want, "clair_http_test_request_total"); err != nil {
t.Error(err)
Expand Down

0 comments on commit 31db514

Please sign in to comment.