test: stop task scheduler between test runs (#1311)

sync: remove sync WaitGroup, it's stopped with context
sync: onDemand will always try to sync newest image when a tag is used
if a digest is used then onDemand will serve local image
test(sync): fix flaky coverage in sync package
closes #1294

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu
2023-03-29 21:37:58 +03:00
committed by GitHub
parent 0ae35e973a
commit 3dd3c46ee3
8 changed files with 499 additions and 489 deletions
+9 -1
View File
@@ -283,6 +283,8 @@ type Controller interface {
type ControllerManager struct {
controller Controller
// used to stop background tasks(goroutines) - task scheduler
cancelRoutinesFunc context.CancelFunc
}
func (cm *ControllerManager) RunServer(ctx context.Context) {
@@ -293,7 +295,8 @@ func (cm *ControllerManager) RunServer(ctx context.Context) {
}
func (cm *ControllerManager) StartServer() {
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
cm.cancelRoutinesFunc = cancel
if err := cm.controller.Init(ctx); err != nil {
panic(err)
@@ -305,6 +308,11 @@ func (cm *ControllerManager) StartServer() {
}
func (cm *ControllerManager) StopServer() {
// stop background tasks - task scheduler
if cm.cancelRoutinesFunc != nil {
cm.cancelRoutinesFunc()
}
cm.controller.Shutdown()
}