Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
test: count unique servers which replies
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Leigh <allenlsy@gmail.com>
  • Loading branch information
allenlsy committed Sep 1, 2021
1 parent e427332 commit c901324
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/e2e/e2e_deployment_client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

. "github.com/openservicemesh/osm/tests/framework"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -20,6 +21,13 @@ var _ = OSMDescribe("Test HTTP traffic from N deployment client -> 1 deployment
Bucket: 2,
},
func() {
const (
// to name the header we will use to identify the server that replies
HTTPHeaderName = "podname"
)

var maxTestDuration = 150 * time.Second

Context("DeploymentsClientServer", func() {
const destApp = "server"
const sourceAppBaseName = "client"
Expand Down Expand Up @@ -57,13 +65,28 @@ var _ = OSMDescribe("Test HTTP traffic from N deployment client -> 1 deployment
Name: "server",
Namespace: destApp,
ReplicaCount: int32(replicaSetPerService),
Image: "kennethreitz/httpbin",
Image: "simonkowallik/httpbin",
Ports: []int{DefaultUpstreamServicePort},
Command: HttpbinCmd,
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())

// Expose an env variable such as XHTTPBIN_X_POD_NAME:
// This httpbin fork will pick certain env variable formats and reply the values as headers.
// We will expose pod name as one of these env variables, and will use it
// to identify the pod that replies to the request, and validate the test
deploymentDef.Spec.Template.Spec.Containers[0].Env = []v1.EnvVar{
{
Name: fmt.Sprintf("XHTTPBIN_%s", HTTPHeaderName),
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
}

_, err = Td.CreateServiceAccount(destApp, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateDeployment(destApp, deploymentDef)
Expand Down Expand Up @@ -151,6 +174,7 @@ var _ = OSMDescribe("Test HTTP traffic from N deployment client -> 1 deployment
}

var results HTTPMultipleResults
var serversSeen map[string]bool = map[string]bool{} // Just counts unique servers seen
success := Td.WaitForRepeatedSuccess(func() bool {
// Issue all calls, get results
results = Td.MultipleHTTPRequest(&requests)
Expand All @@ -164,10 +188,19 @@ var _ = OSMDescribe("Test HTTP traffic from N deployment client -> 1 deployment
if podResult.Err != nil || podResult.StatusCode != 200 {
return false
}
// We should see pod header populated
dstPod, ok := podResult.Headers[HTTPHeaderName]
if ok {
// Store and mark that we have seen a response for this server pod
serversSeen[dstPod] = true
}
}
}
Td.T.Logf("Unique servers replied %d/%d", len(serversSeen), replicaSetPerService)
Expect(len(serversSeen)).To(Equal(replicaSetPerService))

return true
}, 5, 150*time.Second)
}, 5, maxTestDuration)

Expect(success).To(BeTrue())
})
Expand Down

0 comments on commit c901324

Please sign in to comment.