Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Speed up K8sServicesTest #11550

Merged
merged 6 commits into from May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/helpers/wrappers.go
Expand Up @@ -73,6 +73,17 @@ func CurlFail(endpoint string, optionalValues ...interface{}) string {
CurlConnectTimeout, CurlMaxTimeout, endpoint, statsInfo)
}

// CurlFailNoStats does the same as CurlFail() except that it does not print
// the stats info.
func CurlFailNoStats(endpoint string, optionalValues ...interface{}) string {
if len(optionalValues) > 0 {
endpoint = fmt.Sprintf(endpoint, optionalValues...)
}
return fmt.Sprintf(
`curl --path-as-is -s -D /dev/stderr --fail --connect-timeout %[1]d --max-time %[2]d %[3]s`,
CurlConnectTimeout, CurlMaxTimeout, endpoint)
}

// CurlWithHTTPCode retunrs the string representation of the curl command which
// only outputs the HTTP code returned by its execution against the specified
// endpoint. It takes a variadic optinalValues argument. This is passed on to
Expand Down
34 changes: 14 additions & 20 deletions test/k8sT/Services.go
Expand Up @@ -136,23 +136,18 @@ var _ = Describe("K8sServicesTest", func() {
}

testCurlRequest := func(clientPodLabel, url string) {
pods, err := kubectl.GetPodNames(helpers.DefaultNamespace, clientPodLabel)
ExpectWithOffset(1, err).Should(BeNil(), "cannot retrieve pod names by filter %q", testDSClient)
// A DS with client is running in each node. So we try from each node
// that can connect to the service. To make sure that the cross-node
// service connectivity is correct we tried 10 times, so balance in the
// two nodes
pods, err := kubectl.GetPodNames(helpers.DefaultNamespace, clientPodLabel)
ExpectWithOffset(1, err).Should(BeNil(), "cannot retrieve pod names by filter %q", testDSClient)
count := 10
cmd := fmt.Sprintf(`/bin/sh -c 'for i in $(seq 1 %d); do %s; done'`, count, helpers.CurlFailNoStats(url))
for _, pod := range pods {
tries := 10
By("Making %d curl requests from %q to %q", tries, pod, url)
for i := 1; i <= tries; i++ {
res := kubectl.ExecPodCmd(
helpers.DefaultNamespace, pod,
helpers.CurlFail(url))
ExpectWithOffset(1, res).Should(helpers.CMDSuccess(),
"Pod %q can not connect to service %q (failed in request %d/%d)",
pod, url, i, tries)
}
By("Making %d curl requests from %s pod to service %s", count, pod, url)
res := kubectl.ExecPodCmd(helpers.DefaultNamespace, pod, cmd)
ExpectWithOffset(1, res).Should(helpers.CMDSuccess(), "Request from %s pod to service %s failed", pod, url)
}
}

Expand Down Expand Up @@ -378,14 +373,13 @@ var _ = Describe("K8sServicesTest", func() {
}

doRequests := func(url string, count int, fromPod string) {
By("Making %d curl requests from %s to %q", count, fromPod, url)
for i := 1; i <= count; i++ {
res, err := kubectl.ExecInHostNetNS(context.TODO(), fromPod, helpers.CurlFail(url))
ExpectWithOffset(1, err).To(BeNil(), "Cannot run curl in host netns")
ExpectWithOffset(1, res).Should(helpers.CMDSuccess(),
"%s host can not connect to service %q (failed in request %d/%d)",
fromPod, url, i, count)
}
By("Making %d curl requests from pod (host netns) %s to %q", count, fromPod, url)
cmd := fmt.Sprintf(`/bin/sh -c 'for i in $(seq 1 %d); do %s; done'`, count,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy mother of nesting. But I guess there is no way around this (unless we want to also parallelize curl calls?).

helpers.CurlFailNoStats(url))
res, err := kubectl.ExecInHostNetNS(context.TODO(), fromPod, cmd)
ExpectWithOffset(1, err).To(BeNil(), "Cannot run curl in host netns")
ExpectWithOffset(1, res).Should(helpers.CMDSuccess(),
"Request from %s to service %s failed", fromPod, url)
}

failRequests := func(url string, count int, fromPod string) {
Expand Down