Skip to content

Commit

Permalink
fix: consider noop operator for in short circuit logic
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Warmuth <[email protected]>
  • Loading branch information
warber committed Nov 29, 2024
1 parent 1b76ca0 commit a714c3e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
20 changes: 11 additions & 9 deletions openfeature/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,18 @@ func (c *Client) evaluate(
c.finallyHooks(ctx, hookCtx, providerInvocationClientApiHooks, options)
}()

// short circuit if provider is in NOT READY state
if c.State() == NotReadyState {
c.errorHooks(ctx, hookCtx, providerInvocationClientApiHooks, ProviderNotReadyError, options)
return evalDetails, ProviderNotReadyError
}
if _, ok := provider.(NoopProvider); !ok {
// short circuit if provider is in NOT READY state
if c.State() == NotReadyState {
c.errorHooks(ctx, hookCtx, providerInvocationClientApiHooks, ProviderNotReadyError, options)
return evalDetails, ProviderNotReadyError
}

// short circuit if provider is in FATAL state
if c.State() == FatalState {
c.errorHooks(ctx, hookCtx, providerInvocationClientApiHooks, ProviderFatalError, options)
return evalDetails, ProviderFatalError
// short circuit if provider is in FATAL state
if c.State() == FatalState {
c.errorHooks(ctx, hookCtx, providerInvocationClientApiHooks, ProviderFatalError, options)
return evalDetails, ProviderFatalError
}
}

evalCtx, err = c.beforeHooks(ctx, hookCtx, apiClientInvocationProviderHooks, evalCtx, options)
Expand Down
21 changes: 19 additions & 2 deletions openfeature/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openfeature
import (
"context"
"errors"
"math"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -1385,7 +1386,24 @@ func TestRequirement_1_7_6(t *testing.T) {
mockHook.EXPECT().Error(gomock.Any(), gomock.Any(), ProviderNotReadyError, gomock.Any())
mockHook.EXPECT().Finally(gomock.Any(), gomock.Any(), gomock.Any())

client := GetApiInstance().GetNamedClient(t.Name())
notReadyEventingProvider := struct {
FeatureProvider
StateHandler
EventHandler
}{
NoopProvider{},
&stateHandlerForTests{
initF: func(e EvaluationContext) error {
<-time.After(math.MaxInt)
return nil
},
},
&ProviderEventing{},
}

GetApiInstance().SetProvider(notReadyEventingProvider)

Check failure on line 1404 in openfeature/client_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `(github.com/open-feature/go-sdk/openfeature.IEvaluation).SetProvider` is not checked (errcheck)

client := GetApiInstance().GetNamedClient("somOtherClient")
client.AddHooks(mockHook)

if client.State() != NotReadyState {
Expand All @@ -1401,7 +1419,6 @@ func TestRequirement_1_7_6(t *testing.T) {
if res != defaultVal {
t.Fatalf("expected resolved boolean value to default to %t, got %t", defaultVal, res)
}

}

// The client MUST default, run error hooks, and indicate an error if flag resolution is attempted while the provider
Expand Down

0 comments on commit a714c3e

Please sign in to comment.