Skip to content

Commit

Permalink
Merge pull request #98023 from tkashem/fix-test
Browse files Browse the repository at this point in the history
fix apf controller unit test
  • Loading branch information
k8s-ci-robot committed Jan 13, 2021
2 parents a28c802 + f20c6cb commit e059af6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ func (cfgCtlr *configController) updateObservations() {
}
}

// used from the unit tests only.
func (cfgCtlr *configController) getPriorityLevelState(plName string) *priorityLevelState {
cfgCtlr.lock.Lock()
defer cfgCtlr.lock.Unlock()
return cfgCtlr.priorityLevelStates[plName]
}

func (cfgCtlr *configController) Run(stopCh <-chan struct{}) error {
defer utilruntime.HandleCrash()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ var mandPLs = func() map[string]*flowcontrol.PriorityLevelConfiguration {
return ans
}()

// in general usage, the boolean returned may be inaccurate by the time the caller examines it.
func (cfgCtlr *configController) hasPriorityLevelState(plName string) bool {
cfgCtlr.lock.Lock()
defer cfgCtlr.lock.Unlock()
return cfgCtlr.priorityLevelStates[plName] != nil
}

type ctlrTestState struct {
t *testing.T
cfgCtlr *configController
Expand Down Expand Up @@ -380,10 +387,7 @@ func TestAPFControllerWithGracefulShutdown(t *testing.T) {

// ensure that the controller has run its first loop.
err := wait.PollImmediate(100*time.Millisecond, 5*time.Second, func() (done bool, err error) {
if controller.getPriorityLevelState(plName) == nil {
return false, nil
}
return true, nil
return controller.hasPriorityLevelState(plName), nil
})
if err != nil {
t.Errorf("expected the controller to reconcile the priority level configuration object: %s, error: %s", plName, err)
Expand Down

0 comments on commit e059af6

Please sign in to comment.