Skip to content

Commit

Permalink
Improved test stability when executed with -race
Browse files Browse the repository at this point in the history
  • Loading branch information
eranharel committed Jul 23, 2019
1 parent ef9df5f commit 386ffd9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestHealthWithBogusCheck(t *testing.T) {
ExecutionPeriod: 1,
InitialDelay: 1,
})
defer h.DeregisterAll()

assert.Error(t, err, "register bogus check should fail")
assert.Contains(t, err.Error(), "misconfigured check", "fail message")
Expand All @@ -51,8 +52,6 @@ func TestHealthWithBogusCheck(t *testing.T) {
results, healthy := h.Results()
assert.True(t, healthy, "results after bogus register")
assert.Empty(t, results, "results after bogus register")

h.DeregisterAll()
}

func TestRegisterDeregister(t *testing.T) {
Expand Down Expand Up @@ -147,6 +146,7 @@ func TestHealthMetrics(t *testing.T) {
h := New()
registerCheck(h, failingCheckName, false)
registerCheck(h, passingCheckName, true)
defer h.DeregisterAll()

// await first execution
time.Sleep(21 * time.Millisecond)
Expand All @@ -169,8 +169,6 @@ func TestHealthMetrics(t *testing.T) {
assert.Equal(t, 2, len(checksTimeData), "num timing rows")
assert.Equal(t, int64(2), checksTimeData[passingCheckName].(*view.DistributionData).Count, "passing check timing measurement count")
assert.Equal(t, int64(2), checksTimeData[failingCheckName].(*view.DistributionData).Count, "failing check timing measurement count")

h.DeregisterAll()
}

func simplifyRows(viewName string) (check2data map[string]view.AggregationData) {
Expand Down
2 changes: 2 additions & 0 deletions http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestHandleHealthJSON_longFormatPassingCheck(t *testing.T) {
if err != nil {
t.Error("Failed to register check: ", err)
}
defer h.DeregisterAll()

resp := execReq(h, true)
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode, "status before first run")
Expand Down Expand Up @@ -78,6 +79,7 @@ func TestHandleHealthJSON_shortFormatPassingCheck(t *testing.T) {
if err != nil {
t.Error("Failed to register check: ", err)
}
defer h.DeregisterAll()

resp := execReq(h, false)
assert.Equal(t, http.StatusServiceUnavailable, resp.StatusCode, "status before first run")
Expand Down

0 comments on commit 386ffd9

Please sign in to comment.