Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions circuitbreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,12 @@ func TestThresholdBreakerResets(t *testing.T) {
}

func TestTimeoutBreaker(t *testing.T) {
wait := make(chan struct{})

c := clock.NewMock()
called := int32(0)
var called int32

circuit := func() error {
wait <- struct{}{}
atomic.AddInt32(&called, 1)
<-wait
c.Add(time.Millisecond * 3)
return nil
}

Expand All @@ -341,19 +338,16 @@ func TestTimeoutBreaker(t *testing.T) {
errc := make(chan error)
go func() { errc <- cb.Call(circuit, time.Millisecond) }()

<-wait
c.Add(time.Millisecond * 3)
wait <- struct{}{}

err := <-errc
if err == nil {
t.Fatal("expected timeout breaker to return an error")
}

if atomic.LoadInt32(&called) != 1 {
t.Fatal("expected circuit be called once")
}

go cb.Call(circuit, time.Millisecond)
<-wait
c.Add(time.Millisecond * 3)
wait <- struct{}{}

if !cb.Tripped() {
t.Fatal("expected timeout breaker to be open")
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/rubyist/circuitbreaker

go 1.21.0

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a
github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea h1:sKwxy1H95npauwu8vtF95vG/syrL0p8fSZo/XlDg5gk=
github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea/go.mod h1:1VcHEd3ro4QMoHfiNl/j7Jkln9+KQuorp0PItHMJYNg=