Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't return error when there is a good projectConfig in polling manager #179

Merged
merged 4 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/config/polling_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func (cm *PollingProjectConfigManager) SyncConfig(datafile []byte) {

if e != nil {
cmLogger.Error(fmt.Sprintf("request returned with http code=%d", code), e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can tone this down to a Warning. @mjc1283 or @mikecdavis what do you guys think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted with @mjc1283 offline and this is in line with what the other SDKs do.

cm.err = e
cm.err = nil
if cm.projectConfig == nil {
cm.err = e
}
return
}
}
Expand All @@ -103,7 +106,10 @@ func (cm *PollingProjectConfigManager) SyncConfig(datafile []byte) {

cm.configLock.Lock()
closeMutex := func() {
cm.err = err
cm.err = nil
if cm.projectConfig == nil {
cm.err = err
}
cm.configLock.Unlock()
}
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions pkg/config/polling_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,39 @@ func TestNewPollingProjectConfigManagerWithDifferentDatafileRevisions(t *testing
assert.Equal(t, projectConfig2, actual)
}

func TestNewPollingProjectConfigManagerWithErrorHandling(t *testing.T) {
mockDatafile1 := []byte("NOT-VALID")
mockDatafile2 := []byte(`{"revision":"43","botFiltering":false}`)

projectConfig1, _ := datafileprojectconfig.NewDatafileProjectConfig(mockDatafile1)
projectConfig2, _ := datafileprojectconfig.NewDatafileProjectConfig(mockDatafile2)
mockRequester := new(MockRequester)
mockRequester.On("Get", []utils.Header(nil)).Return(mockDatafile1, 200, nil)

// Test we fetch using requester
sdkKey := "test_sdk_key"

exeCtx := utils.NewCancelableExecutionCtx()
configManager := NewPollingProjectConfigManager(sdkKey, Requester(mockRequester))
configManager.Start(exeCtx)
mockRequester.AssertExpectations(t)

actual, err := configManager.GetConfig() // polling for bad file
assert.NotNil(t, err)
assert.Nil(t, actual)
assert.Nil(t, projectConfig1)

configManager.SyncConfig(mockDatafile2) // polling for good file
actual, err = configManager.GetConfig()
assert.Nil(t, err)
assert.Equal(t, projectConfig2, actual)

configManager.SyncConfig(mockDatafile1) // polling for bad file, error not null but good project
actual, err = configManager.GetConfig()
assert.Nil(t, err)
assert.Equal(t, projectConfig2, actual)
}

func TestNewPollingProjectConfigManagerOnDecision(t *testing.T) {
mockDatafile1 := []byte(`{"revision":"42","botFiltering":true}`)
mockDatafile2 := []byte(`{"revision":"43","botFiltering":false}`)
Expand Down