diff --git a/hoglet_test.go b/hoglet_test.go index a03c963..70215e1 100644 --- a/hoglet_test.go +++ b/hoglet_test.go @@ -92,6 +92,23 @@ func TestBreaker_ctx_parameter_not_cancelled(t *testing.T) { assert.NoError(t, ctx.Err()) } +func TestCircuit_ignored_context_cancellation_still_returned(t *testing.T) { + b, err := NewCircuit( + func(ctx context.Context, _ any) (string, error) { + return "expected", ctx.Err() + }, + nil, + WithFailureCondition(IgnoreContextCancelation)) + require.NoError(t, err) + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + out, err := b.Call(ctx, nil) + assert.ErrorIs(t, err, context.Canceled) + assert.Equal(t, "expected", out) +} + // mockBreaker is a mock implementation of the [Breaker] interface that opens or closes depending on the last observed // failure. type mockBreaker struct{} diff --git a/options.go b/options.go index f62dae7..84cc2e2 100644 --- a/options.go +++ b/options.go @@ -29,6 +29,8 @@ func WithHalfOpenDelay(delay time.Duration) Option { // If the provided function returns true, the error is considered a failure and the breaker may open (depending on the // breaker logic). // The default filter considers all non-nil errors as failures (err != nil). +// +// This does not modify the error returned by [Circuit.Call]. It only affects the circuit itself. func WithFailureCondition(condition func(error) bool) Option { return optionFunc(func(o *options) error { o.isFailure = condition