wait for garbagecollector to be synced in test

pull/6/head
Chao Xu 2017-03-14 16:19:33 -07:00
parent ab9b299c30
commit 0605ba7a6d
2 changed files with 19 additions and 1 deletions

View File

@ -125,6 +125,10 @@ func (gc *GarbageCollector) Run(workers int, stopCh <-chan struct{}) {
glog.Infof("Garbage Collector: Shutting down")
}
func (gc *GarbageCollector) HasSynced() bool {
return gc.dependencyGraphBuilder.HasSynced()
}
func (gc *GarbageCollector) runAttemptToDeleteWorker() {
for gc.attemptToDeleteWorker() {
}

View File

@ -37,6 +37,7 @@ import (
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
@ -607,7 +608,7 @@ func TestBlockingOwnerRefDoesBlock(t *testing.T) {
s, gc, clientSet := setup(t)
defer s.Close()
ns := framework.CreateTestingNamespace("gc-foreground2", s, t)
ns := framework.CreateTestingNamespace("gc-foreground3", s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
podClient := clientSet.Core().Pods(ns.Name)
@ -632,6 +633,19 @@ func TestBlockingOwnerRefDoesBlock(t *testing.T) {
go gc.Run(5, stopCh)
defer close(stopCh)
// this makes sure the garbage collector will have added the pod to its
// dependency graph before handling the foreground deletion of the rc.
timeout := make(chan struct{})
go func() {
select {
case <-time.After(5 * time.Second):
close(timeout)
}
}()
if !cache.WaitForCacheSync(timeout, gc.HasSynced) {
t.Fatalf("failed to wait for garbage collector to be synced")
}
err = rcClient.Delete(toBeDeletedRCName, getForegroundOptions())
if err != nil {
t.Fatalf("Failed to delete the rc: %v", err)