Merge pull request #98023 from tkashem/fix-test

fix apf controller unit test
This commit is contained in:
Kubernetes Prow Robot 2021-01-13 14:17:26 -08:00 committed by GitHub
commit e059af6406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View File

@ -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()

View File

@ -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
@ -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)