Skip to content

Commit

Permalink
Retry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris S. Kim committed Oct 5, 2023
1 parent d157d93 commit 9da2d0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
26 changes: 14 additions & 12 deletions agent/health_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,21 @@ func TestHealthServiceChecks_NodeMetaFilter(t *testing.T) {
t.Fatalf("err: %v", err)
}

req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
resp = httptest.NewRecorder()
obj, err = a.srv.HealthServiceChecks(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
}
assertIndex(t, resp)
retry.Run(t, func(r *retry.R) {
req, _ = http.NewRequest("GET", "/v1/health/checks/consul?dc=dc1&node-meta=somekey:somevalue", nil)
resp = httptest.NewRecorder()
obj, err = a.srv.HealthServiceChecks(resp, req)
if err != nil {
r.Fatalf("err: %v", err)
}
assertIndex(r, resp)

// Should be 1 health check for consul
nodes = obj.(structs.HealthChecks)
if len(nodes) != 1 {
t.Fatalf("bad: %v", obj)
}
// Should be 1 health check for consul
nodes = obj.(structs.HealthChecks)
if len(nodes) != 1 {
r.Fatalf("bad: %v", obj)
}
})
}

func TestHealthServiceChecks_Filtering(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1628,8 +1628,10 @@ func TestAllowedNets(t *testing.T) {
}

// assertIndex tests that X-Consul-Index is set and non-zero
func assertIndex(t *testing.T, resp *httptest.ResponseRecorder) {
t.Helper()
func assertIndex(t require.TestingT, resp *httptest.ResponseRecorder) {
if tt, ok := t.(*testing.T); ok {
tt.Helper()
}
require.NoError(t, checkIndex(resp))
}

Expand Down
4 changes: 4 additions & 0 deletions agent/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func skipIfShortTesting(t *testing.T) {
}

func recordPromMetrics(t require.TestingT, a *TestAgent, respRec *httptest.ResponseRecorder) {
if tt, ok := t.(*testing.T); ok {
tt.Helper()
}

req, err := http.NewRequest("GET", "/v1/agent/metrics?format=prometheus", nil)
require.NoError(t, err, "Failed to generate new http request.")

Expand Down

0 comments on commit 9da2d0c

Please sign in to comment.