Skip to content

Commit

Permalink
Added timeout for go routine that listens to default setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Dec 8, 2023
1 parent 3f0f79a commit 7206324
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
14 changes: 5 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ func NewClient(options ...ConfigOption) (*Client, error) {
}()

if uc.options.url == "" {
return nil, fmt.Errorf("Unleash server URL missing")
return nil, fmt.Errorf("unleash server URL missing")
}

if strings.HasSuffix(uc.options.url, deprecatedSuffix) {
uc.warn(fmt.Errorf("Unleash server URL %s should no longer link directly to /features", uc.options.url))
uc.warn(fmt.Errorf("unleash server URL %s should no longer link directly to /features", uc.options.url))
uc.options.url = strings.TrimSuffix(uc.options.url, deprecatedSuffix)
}

Expand All @@ -148,7 +148,7 @@ func NewClient(options ...ConfigOption) (*Client, error) {
}

if uc.options.appName == "" {
return nil, fmt.Errorf("Unleash client appName missing")
return nil, fmt.Errorf("unleash client appName missing")
}

if uc.options.instanceId == "" {
Expand Down Expand Up @@ -358,7 +358,7 @@ func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context cont

enabledResult := uc.isEnabled(parent.Feature, WithContext(context))
// According to the schema, if the enabled property is absent we assume it's true.
if parent.Enabled == nil || *parent.Enabled == true {
if parent.Enabled == nil || *parent.Enabled {
if parent.Variants != nil && len(*parent.Variants) > 0 && enabledResult.Variant != nil {
return enabledResult.Enabled && contains(*parent.Variants, enabledResult.Variant.Name)
}
Expand All @@ -372,11 +372,7 @@ func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context cont
return dependenciesSatisfied(parent.(api.Dependency))
})

if !allDependenciesSatisfied {
return false
}

return true
return allDependenciesSatisfied
}

// GetVariant queries a variant as the specified feature is enabled.
Expand Down
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestClientWithoutListener(t *testing.T) {
assert.Nil(err, "client should not return an error")

go func() {
timeout := time.After(1 * time.Second)
for {
select {
case e := <-client.Errors():
Expand All @@ -45,6 +46,8 @@ func TestClientWithoutListener(t *testing.T) {
return
case <-client.Count():
case <-client.Sent():
case <-timeout:
return
}
}
}()
Expand Down
1 change: 1 addition & 0 deletions internal/strategies/flexible_rollout_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build norace
// +build norace

package strategies
Expand Down
2 changes: 1 addition & 1 deletion metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestMetrics_DoPost(t *testing.T) {
WithUrl(mockerServer),
WithAppName(mockAppName),
WithInstanceId(mockInstanceId),
WithListener(mockListener),
WithListener(&DebugListener{}),
)

assert.Nil(err, "client should not return an error")
Expand Down

0 comments on commit 7206324

Please sign in to comment.