Skip to content

Commit

Permalink
CR fixes: reverse test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
segevda committed Dec 31, 2024
1 parent 34ae727 commit 52b65ca
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,35 +1458,35 @@ func TestClientCircuitBreaker(t *testing.T) {
resp, err := c.R().Get(ts.URL + "/500")
assertErrorIs(t, ErrCircuitBreakerOpen, err)
assertNil(t, resp)
assertEqual(t, c.circuitBreaker.getState(), circuitBreakerStateOpen)
assertEqual(t, circuitBreakerStateOpen, c.circuitBreaker.getState())

time.Sleep(timeout + 1*time.Millisecond)
assertEqual(t, c.circuitBreaker.getState(), circuitBreakerStateHalfOpen)
assertEqual(t, circuitBreakerStateHalfOpen, c.circuitBreaker.getState())

resp, err = c.R().Get(ts.URL + "/500")
assertError(t, err)
assertEqual(t, c.circuitBreaker.getState(), circuitBreakerStateOpen)
assertEqual(t, circuitBreakerStateOpen, c.circuitBreaker.getState())

time.Sleep(timeout + 1*time.Millisecond)
assertEqual(t, c.circuitBreaker.getState(), circuitBreakerStateHalfOpen)
assertEqual(t, circuitBreakerStateHalfOpen, c.circuitBreaker.getState())

for i := uint32(0); i < successThreshold; i++ {
_, err := c.R().Get(ts.URL + "/200")
assertNil(t, err)
}
assertEqual(t, c.circuitBreaker.getState(), circuitBreakerStateClosed)
assertEqual(t, circuitBreakerStateClosed, c.circuitBreaker.getState())

resp, err = c.R().Get(ts.URL + "/200")
assertNil(t, err)
assertEqual(t, http.StatusOK, resp.StatusCode())

resp, err = c.R().Get(ts.URL + "/500")
assertError(t, err)
assertEqual(t, c.circuitBreaker.failCount.Load(), uint32(1))
assertEqual(t, uint32(1), c.circuitBreaker.failCount.Load())

time.Sleep(timeout)

resp, err = c.R().Get(ts.URL + "/500")
assertError(t, err)
assertEqual(t, c.circuitBreaker.failCount.Load(), uint32(1))
assertEqual(t, uint32(1), c.circuitBreaker.failCount.Load())
}

0 comments on commit 52b65ca

Please sign in to comment.