Merge pull request #5383 from wojtek-t/kubelet_test

Speedup pkg/kubelet/runonce_test.go
pull/6/head
Victor Marmol 2015-03-12 10:22:03 -07:00
commit 2939abb6cb
2 changed files with 7 additions and 6 deletions

View File

@ -42,7 +42,7 @@ func (kl *Kubelet) RunOnce(updates <-chan PodUpdate) ([]RunPodResult, error) {
select { select {
case u := <-updates: case u := <-updates:
glog.Infof("processing manifest with %d pods", len(u.Pods)) glog.Infof("processing manifest with %d pods", len(u.Pods))
result, err := kl.runOnce(u.Pods) result, err := kl.runOnce(u.Pods, RunOnceRetryDelay)
glog.Infof("finished processing %d pods", len(u.Pods)) glog.Infof("finished processing %d pods", len(u.Pods))
return result, err return result, err
case <-time.After(RunOnceManifestDelay): case <-time.After(RunOnceManifestDelay):
@ -51,7 +51,7 @@ func (kl *Kubelet) RunOnce(updates <-chan PodUpdate) ([]RunPodResult, error) {
} }
// runOnce runs a given set of pods and returns their status. // runOnce runs a given set of pods and returns their status.
func (kl *Kubelet) runOnce(pods []api.BoundPod) (results []RunPodResult, err error) { func (kl *Kubelet) runOnce(pods []api.BoundPod, retryDelay time.Duration) (results []RunPodResult, err error) {
if kl.dockerPuller == nil { if kl.dockerPuller == nil {
kl.dockerPuller = dockertools.NewDockerPuller(kl.dockerClient, kl.pullQPS, kl.pullBurst) kl.dockerPuller = dockertools.NewDockerPuller(kl.dockerClient, kl.pullQPS, kl.pullBurst)
} }
@ -61,7 +61,7 @@ func (kl *Kubelet) runOnce(pods []api.BoundPod) (results []RunPodResult, err err
for i := range pods { for i := range pods {
pod := pods[i] // Make a copy pod := pods[i] // Make a copy
go func() { go func() {
err := kl.runPod(pod) err := kl.runPod(pod, retryDelay)
ch <- RunPodResult{&pod, err} ch <- RunPodResult{&pod, err}
}() }()
} }
@ -87,8 +87,8 @@ func (kl *Kubelet) runOnce(pods []api.BoundPod) (results []RunPodResult, err err
} }
// runPod runs a single pod and wait until all containers are running. // runPod runs a single pod and wait until all containers are running.
func (kl *Kubelet) runPod(pod api.BoundPod) error { func (kl *Kubelet) runPod(pod api.BoundPod, retryDelay time.Duration) error {
delay := RunOnceRetryDelay delay := retryDelay
retry := 0 retry := 0
for { for {
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false) dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false)

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"testing" "testing"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
@ -140,7 +141,7 @@ func TestRunOnce(t *testing.T) {
}, },
}, },
}, },
}) }, time.Millisecond)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }