Skip to content

Commit

Permalink
Fix concurrency issues in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa authored and maistra-bot committed Sep 20, 2022
1 parent b5a9e08 commit a37540b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/informers/informer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func TestSharedInformerWatchDisruption(t *testing.T) {
}

for _, listener := range listeners {
listener.lock.Lock()
listener.receivedItemNames = []string{}
listener.lock.Unlock()
}

listenerNoResync.expectedItemNames = sets.NewString("pod2", "pod3")
Expand Down Expand Up @@ -245,6 +247,7 @@ func TestMultiNamespaceInformerEventHandlers(t *testing.T) {
cm1 := internaltesting.NewConfigMap(namespaces[0], "cm1", nil)
cm2 := internaltesting.NewConfigMap(namespaces[1], "cm2", nil)

lock := sync.RWMutex{}
addFuncCalled := false
updateFuncCalled := false
deleteFuncCalled := false
Expand All @@ -271,13 +274,19 @@ func TestMultiNamespaceInformerEventHandlers(t *testing.T) {

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(_ interface{}) {
lock.Lock()
addFuncCalled = true
lock.Unlock()
},
UpdateFunc: func(_, _ interface{}) {
lock.Lock()
updateFuncCalled = true
lock.Unlock()
},
DeleteFunc: func(_ interface{}) {
lock.Lock()
deleteFuncCalled = true
lock.Unlock()
},
})

Expand Down Expand Up @@ -310,6 +319,8 @@ func TestMultiNamespaceInformerEventHandlers(t *testing.T) {

// Wait for all handler functions to be called.
err = wait.PollImmediate(100*time.Millisecond, 1*time.Minute, func() (bool, error) {
lock.RLock()
defer lock.RUnlock()
return addFuncCalled && updateFuncCalled && deleteFuncCalled, nil
})

Expand Down

0 comments on commit a37540b

Please sign in to comment.