Refactor shutdown e2e tests

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-07-29 11:53:35 -04:00
parent a4f7006dbd
commit a383117e1e
3 changed files with 59 additions and 32 deletions

View file

@ -166,7 +166,7 @@ func waitForPodsDeleted(kubeClientSet kubernetes.Interface, timeout time.Duratio
})
}
// WaitForEndpoints waits for a given amount of time until an endpoint contains.
// WaitForEndpoints waits for a given amount of time until the number of endpoints = expectedEndpoints.
func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration, name, ns string, expectedEndpoints int) error {
if expectedEndpoints == 0 {
return nil
@ -180,16 +180,7 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
assert.Nil(ginkgo.GinkgoT(), err, "getting endpoints")
if len(endpoint.Subsets) == 0 || len(endpoint.Subsets[0].Addresses) == 0 {
return false, nil
}
r := 0
for _, es := range endpoint.Subsets {
r += len(es.Addresses)
}
if r == expectedEndpoints {
if countReadyEndpoints(endpoint) == expectedEndpoints {
return true, nil
}
@ -197,6 +188,19 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
})
}
func countReadyEndpoints(e *core.Endpoints) int {
if e == nil || e.Subsets == nil {
return 0
}
num := 0
for _, sub := range e.Subsets {
num += len(sub.Addresses)
}
return num
}
// podRunningReady checks whether pod p's phase is running and it has a ready
// condition of status true.
func podRunningReady(p *core.Pod) (bool, error) {