fix apf controller unit test
- don't expose the internal states of the apf controller to the caller - return a boolean, instead of the priority level states Kubernetes-commit: f20c6cb2d9060920cae9ff5cade1739c7e0b7f7a
This commit is contained in:
		
							parent
							
								
									a01efc7338
								
							
						
					
					
						commit
						84ce907827
					
				|  | @ -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 { | func (cfgCtlr *configController) Run(stopCh <-chan struct{}) error { | ||||||
| 	defer utilruntime.HandleCrash() | 	defer utilruntime.HandleCrash() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,6 +54,13 @@ var mandPLs = func() map[string]*flowcontrol.PriorityLevelConfiguration { | ||||||
| 	return ans | 	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 { | type ctlrTestState struct { | ||||||
| 	t               *testing.T | 	t               *testing.T | ||||||
| 	cfgCtlr         *configController | 	cfgCtlr         *configController | ||||||
|  | @ -380,10 +387,7 @@ func TestAPFControllerWithGracefulShutdown(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	// ensure that the controller has run its first loop.
 | 	// ensure that the controller has run its first loop.
 | ||||||
| 	err := wait.PollImmediate(100*time.Millisecond, 5*time.Second, func() (done bool, err error) { | 	err := wait.PollImmediate(100*time.Millisecond, 5*time.Second, func() (done bool, err error) { | ||||||
| 		if controller.getPriorityLevelState(plName) == nil { | 		return controller.hasPriorityLevelState(plName), nil | ||||||
| 			return false, nil |  | ||||||
| 		} |  | ||||||
| 		return true, nil |  | ||||||
| 	}) | 	}) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Errorf("expected the controller to reconcile the priority level configuration object: %s, error: %s", plName, err) | 		t.Errorf("expected the controller to reconcile the priority level configuration object: %s, error: %s", plName, err) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue