Wait for markPodsReady goroutine to finish

pull/6/head
Janet Kuo 2017-11-02 14:21:15 -07:00
parent 3233a07ec1
commit 98d26aeb23
1 changed files with 20 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package deployment
import ( import (
"fmt" "fmt"
"net/http/httptest" "net/http/httptest"
"sync"
"testing" "testing"
"time" "time"
@ -208,7 +209,9 @@ func markPodReady(c clientset.Interface, ns string, pod *v1.Pod) error {
// markUpdatedPodsReady manually marks updated Deployment pods status to ready, // markUpdatedPodsReady manually marks updated Deployment pods status to ready,
// until the deployment is complete // until the deployment is complete
func (d *deploymentTester) markUpdatedPodsReady() { func (d *deploymentTester) markUpdatedPodsReady(wg *sync.WaitGroup) {
defer wg.Done()
ns := d.deployment.Namespace ns := d.deployment.Namespace
err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) { err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) {
// We're done when the deployment is complete // We're done when the deployment is complete
@ -265,28 +268,42 @@ func (d *deploymentTester) waitForDeploymentComplete() error {
// while marking updated Deployment pods as ready at the same time. // while marking updated Deployment pods as ready at the same time.
// Uses hard check to make sure rolling update strategy is not violated at any times. // Uses hard check to make sure rolling update strategy is not violated at any times.
func (d *deploymentTester) waitForDeploymentCompleteAndCheckRollingAndMarkPodsReady() error { func (d *deploymentTester) waitForDeploymentCompleteAndCheckRollingAndMarkPodsReady() error {
var wg sync.WaitGroup
// Manually mark updated Deployment pods as ready in a separate goroutine // Manually mark updated Deployment pods as ready in a separate goroutine
go d.markUpdatedPodsReady() wg.Add(1)
go d.markUpdatedPodsReady(&wg)
// Wait for the Deployment status to complete while Deployment pods are becoming ready // Wait for the Deployment status to complete while Deployment pods are becoming ready
err := d.waitForDeploymentCompleteAndCheckRolling() err := d.waitForDeploymentCompleteAndCheckRolling()
if err != nil { if err != nil {
return fmt.Errorf("failed to wait for Deployment %s to complete: %v", d.deployment.Name, err) return fmt.Errorf("failed to wait for Deployment %s to complete: %v", d.deployment.Name, err)
} }
// Wait for goroutine to finish
wg.Wait()
return nil return nil
} }
// waitForDeploymentCompleteAndMarkPodsReady waits for the Deployment to complete // waitForDeploymentCompleteAndMarkPodsReady waits for the Deployment to complete
// while marking updated Deployment pods as ready at the same time. // while marking updated Deployment pods as ready at the same time.
func (d *deploymentTester) waitForDeploymentCompleteAndMarkPodsReady() error { func (d *deploymentTester) waitForDeploymentCompleteAndMarkPodsReady() error {
var wg sync.WaitGroup
// Manually mark updated Deployment pods as ready in a separate goroutine // Manually mark updated Deployment pods as ready in a separate goroutine
go d.markUpdatedPodsReady() wg.Add(1)
go d.markUpdatedPodsReady(&wg)
// Wait for the Deployment status to complete using soft check, while Deployment pods are becoming ready // Wait for the Deployment status to complete using soft check, while Deployment pods are becoming ready
err := d.waitForDeploymentComplete() err := d.waitForDeploymentComplete()
if err != nil { if err != nil {
return fmt.Errorf("failed to wait for Deployment status %s: %v", d.deployment.Name, err) return fmt.Errorf("failed to wait for Deployment status %s: %v", d.deployment.Name, err)
} }
// Wait for goroutine to finish
wg.Wait()
return nil return nil
} }