Skip to content

Commit

Permalink
Fix data race
Browse files Browse the repository at this point in the history
Signed-off-by: chandankumar4 <[email protected]>
  • Loading branch information
chandankumar4 committed Jun 20, 2024
1 parent a61cdfd commit f23d141
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (cm *ConfigManager) RemoveControllerDefinitionConfig(config NumaflowControl
}

func (cm *ConfigManager) GetControllerDefinitionsConfig() map[string]string {
cm.lock.Lock()
defer cm.lock.Unlock()

return cm.rolloutConfig
}

Expand Down
9 changes: 4 additions & 5 deletions internal/util/kubernetes/config_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_watchConfigMaps(t *testing.T) {

clientSet := fake.NewSimpleClientset()
go watchConfigMaps(ctx, clientSet, "default")
time.Sleep(20 * time.Second)
time.Sleep(10 * time.Second)

data, err := os.ReadFile("../../../tests/config/controller-definitions-config.yaml")
assert.NoError(t, err)
Expand All @@ -45,8 +45,7 @@ func Test_watchConfigMaps(t *testing.T) {
assert.NoError(t, err)

// Wait for the controller to process the ConfigMap
time.Sleep(10 * time.Second)

time.Sleep(5 * time.Second)
// Validate the controller definition config is set correctly
definition := config.GetConfigManagerInstance().GetControllerDefinitionsConfig()
assert.Len(t, definition, 2)
Expand All @@ -56,8 +55,8 @@ func Test_watchConfigMaps(t *testing.T) {
assert.NoError(t, err)

// Wait for the controller to process the ConfigMap
time.Sleep(10 * time.Second)

time.Sleep(5 * time.Second)
// Validate the controller definition config is updated correctly
definition = config.GetConfigManagerInstance().GetControllerDefinitionsConfig()
assert.Len(t, definition, 0)
}

0 comments on commit f23d141

Please sign in to comment.