Skip to content

Commit

Permalink
Comparison instead of strict inequality
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Jan 3, 2025
1 parent f171021 commit 11dbff9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/datasystem/data_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ const (
// Refreshed means the SDK has obtained, at least once, the latest known data from LaunchDarkly.
Refreshed = DataAvailability("refreshed")
)

// AtLeast returns true if the DataAvailability is at least as good as the
// other DataAvailability in terms of data quality.
func (da DataAvailability) AtLeast(other DataAvailability) bool {
return da == Refreshed || (da == Cached && other == Defaults)
}
21 changes: 21 additions & 0 deletions internal/datasystem/data_availability_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package datasystem

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDataAvailibilityAtLeast(t *testing.T) {
assert.True(t, Refreshed.AtLeast(Refreshed))
assert.True(t, Refreshed.AtLeast(Cached))
assert.True(t, Refreshed.AtLeast(Defaults))

assert.False(t, Cached.AtLeast(Refreshed))
assert.True(t, Cached.AtLeast(Cached))
assert.True(t, Cached.AtLeast(Defaults))

assert.False(t, Defaults.AtLeast(Refreshed))
assert.False(t, Defaults.AtLeast(Cached))
assert.True(t, Defaults.AtLeast(Defaults))
}
2 changes: 1 addition & 1 deletion ldclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func MakeCustomClient(sdkKey string, config Config, waitFor time.Duration) (*LDC
for {
select {
case <-closeWhenReady:
if client.dataSystem.DataAvailability() != client.dataSystem.TargetAvailability() {
if client.dataSystem.DataAvailability().AtLeast(client.dataSystem.TargetAvailability()) {
loggers.Warn("LaunchDarkly client initialization failed")
return client, ErrInitializationFailed
}
Expand Down

0 comments on commit 11dbff9

Please sign in to comment.