Skip to content

Commit

Permalink
Update distributed_gobreaker_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiyukiMineo authored Dec 28, 2024
1 parent 72138b9 commit 4944c8f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions v2/distributed_gobreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
)

var defaultDCB *DistributedCircuitBreaker[any]
var customDCB *DistributedCircuitBreaker[any]

type storeAdapter struct {
Expand Down Expand Up @@ -55,14 +54,19 @@ func setupTestWithMiniredis(ctx context.Context) (*DistributedCircuitBreaker[any
}

func pseudoSleepStorage(ctx context.Context, dcb *DistributedCircuitBreaker[any], period time.Duration) {
state, _ := dcb.getSharedState(ctx)
state, err := dcb.getSharedState(ctx)
if err != nil {
panic(err)
}

state.Expiry = state.Expiry.Add(-period)
// Reset counts if the interval has passed
if time.Now().After(state.Expiry) {
state.Counts = Counts{}
}
dcb.setSharedState(ctx, state)
if err := dcb.setSharedState(ctx, state); err != nil {
panic(err)
}
}

func successRequest(ctx context.Context, dcb *DistributedCircuitBreaker[any]) error {
Expand Down

0 comments on commit 4944c8f

Please sign in to comment.