From 26142e614c5b4fece26c92c615762fb66b9710d2 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Fri, 31 Aug 2018 19:42:10 +0800 Subject: [PATCH] Wait for Scheduler cache empty. Signed-off-by: Klaus Ma --- pkg/scheduler/scheduler.go | 5 +++++ test/integration/scheduler/taint_test.go | 5 ++++- test/integration/scheduler/util.go | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index e8ec9d1e33..7e038a45a0 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -74,6 +74,11 @@ func (sched *Scheduler) StopEverything() { close(sched.config.StopEverything) } +// Cache returns the cache in scheduler for test to check the data in scheduler. +func (sched *Scheduler) Cache() schedulercache.Cache { + return sched.config.SchedulerCache +} + // Configurator defines I/O, caching, and other functionality needed to // construct a new scheduler. An implementation of this can be seen in // factory.go. diff --git a/test/integration/scheduler/taint_test.go b/test/integration/scheduler/taint_test.go index 6dc9c20287..9392f37db3 100644 --- a/test/integration/scheduler/taint_test.go +++ b/test/integration/scheduler/taint_test.go @@ -104,7 +104,7 @@ func TestTaintNodeByCondition(t *testing.T) { informers.Extensions().V1beta1().DaemonSets(), nil, // CloudProvider cs, - time.Second, // Node monitor grace period + time.Hour, // Node monitor grace period time.Second, // Node startup grace period time.Second, // Node monitor period time.Second, // Pod eviction timeout @@ -125,6 +125,8 @@ func TestTaintNodeByCondition(t *testing.T) { // Waiting for all controller sync. internalInformers.Start(controllerCh) internalInformers.WaitForCacheSync(controllerCh) + informers.Start(controllerCh) + informers.WaitForCacheSync(controllerCh) // ------------------------------------------- // Test TaintNodeByCondition feature. @@ -669,6 +671,7 @@ func TestTaintNodeByCondition(t *testing.T) { cleanupPods(cs, t, pods) cleanupNodes(cs, t) + waitForSchedulerCacheCleanup(context.scheduler, t) }) } } diff --git a/test/integration/scheduler/util.go b/test/integration/scheduler/util.go index 8d5785674a..c56b8b63d0 100644 --- a/test/integration/scheduler/util.go +++ b/test/integration/scheduler/util.go @@ -679,3 +679,15 @@ func cleanupPodsInNamespace(cs clientset.Interface, t *testing.T, ns string) { t.Errorf("error while waiting for pods in namespace %v: %v", ns, err) } } + +func waitForSchedulerCacheCleanup(sched *scheduler.Scheduler, t *testing.T) { + schedulerCacheIsEmpty := func() (bool, error) { + snapshot := sched.Cache().Snapshot() + + return len(snapshot.Nodes) == 0 && len(snapshot.AssumedPods) == 0, nil + } + + if err := wait.Poll(time.Second, wait.ForeverTestTimeout, schedulerCacheIsEmpty); err != nil { + t.Errorf("Failed to wait for scheduler cache cleanup: %v", err) + } +}