Strip whitespace when comparing endpoints in services test.

This commit is contained in:
Prashanth Balasubramanian 2016-02-25 13:09:17 -08:00
parent df234d83cd
commit 9be53e6319
2 changed files with 20 additions and 11 deletions

View File

@ -1380,25 +1380,34 @@ func verifyServeHostnameServiceUp(c *client.Client, ns, host string, expectedPod
return output return output
}, },
} }
sort.StringSlice(expectedPods).Sort()
expectedEndpoints := sets.NewString(expectedPods...)
By(fmt.Sprintf("verifying service has %d reachable backends", len(expectedPods))) By(fmt.Sprintf("verifying service has %d reachable backends", len(expectedPods)))
for _, cmdFunc := range commands { for _, cmdFunc := range commands {
passed := false passed := false
gotPods := []string{} gotEndpoints := sets.NewString()
// Retry cmdFunc for a while // Retry cmdFunc for a while
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) { for start := time.Now(); time.Since(start) < kubeProxyLagTimeout; time.Sleep(5 * time.Second) {
pods := strings.Split(strings.TrimSpace(cmdFunc()), "\n") for _, endpoint := range strings.Split(cmdFunc(), "\n") {
// Uniq pods before the sort because inserting them into a set trimmedEp := strings.TrimSpace(endpoint)
// (which is implemented using dicts) can re-order them. if trimmedEp != "" {
gotPods = sets.NewString(pods...).List() gotEndpoints.Insert(trimmedEp)
if api.Semantic.DeepEqual(gotPods, expectedPods) { }
}
if expectedEndpoints.Equal(gotEndpoints) {
passed = true passed = true
break break
} }
Logf("Waiting for expected pods for %s: %v, got: %v", serviceIP, expectedPods, gotPods) Logf("Unable to reach the following endpoints of service %s: %v", serviceIP, expectedEndpoints.Difference(gotEndpoints))
} }
if !passed { if !passed {
return fmt.Errorf("service verification failed for: %s, expected %v, got %v", serviceIP, expectedPods, gotPods) // Sort the lists so they're easier to visually diff.
exp := expectedEndpoints.List()
got := gotEndpoints.List()
sort.StringSlice(exp).Sort()
sort.StringSlice(got).Sort()
return fmt.Errorf("service verification failed for: %s\nexpected %v\nreceived %v", serviceIP, exp, got)
} }
} }
return nil return nil

View File

@ -1351,6 +1351,7 @@ func (b kubectlBuilder) withStdinReader(reader io.Reader) *kubectlBuilder {
func (b kubectlBuilder) execOrDie() string { func (b kubectlBuilder) execOrDie() string {
str, err := b.exec() str, err := b.exec()
Logf("stdout: %q", str)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
return str return str
} }
@ -1377,7 +1378,6 @@ func (b kubectlBuilder) exec() (string, error) {
b.cmd.Process.Kill() b.cmd.Process.Kill()
return "", fmt.Errorf("Timed out waiting for command %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr) return "", fmt.Errorf("Timed out waiting for command %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr)
} }
Logf("stdout: %q", stdout.String())
Logf("stderr: %q", stderr.String()) Logf("stderr: %q", stderr.String())
// TODO: trimspace should be unnecessary after switching to use kubectl binary directly // TODO: trimspace should be unnecessary after switching to use kubectl binary directly
return strings.TrimSpace(stdout.String()), nil return strings.TrimSpace(stdout.String()), nil