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

Commit

Permalink
tests/e2e: adding test to individual backend services on trafficsplit
Browse files Browse the repository at this point in the history
To verify new RDS changes:
#1929
  • Loading branch information
eduser25 committed Oct 29, 2020
1 parent c340a7a commit 7092567
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/e2e/common_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type HTTPMultipleRequest struct {
}

// HTTPMultipleResults represents results from a multiple HTTP request call
// results come back as a map[namespace][pod] -> HTTPResults
// results come back as a map["srcNs/srcPod"]["dstNs/dstPod"] -> HTTPResults
type HTTPMultipleResults map[string]map[string]HTTPRequestResult

// MultipleHTTPRequest will issue a list of requests concurrently and return results when all requests have returned
Expand All @@ -115,13 +115,18 @@ func (td *OsmTestData) MultipleHTTPRequest(requests *HTTPMultipleRequest) HTTPMu

// Prepare results
for idx, r := range requests.Sources {
if _, ok := results[r.SourceNs]; !ok {
results[r.SourceNs] = map[string]HTTPRequestResult{}
srcKey := fmt.Sprintf("%s/%s", r.SourceNs, r.SourcePod)
dstKey := r.Destination

if _, ok := results[srcKey]; !ok {
results[srcKey] = map[string]HTTPRequestResult{}
}
if _, ok := results[r.SourceNs][r.SourcePod]; !ok {
results[r.SourceNs][r.SourcePod] = HTTPRequestResult{}
if _, ok := results[srcKey][dstKey]; !ok {
results[srcKey][dstKey] = HTTPRequestResult{}
} else {
td.T.Logf("WARN: Multiple requests from same pod %s. Results will overwrite.", r.SourcePod)
td.T.Logf("No support for more than one request from src to dst. (%s to %s).Ignoring.",
srcKey, dstKey)
continue
}

wg.Add(1)
Expand All @@ -133,7 +138,7 @@ func (td *OsmTestData) MultipleHTTPRequest(requests *HTTPMultipleRequest) HTTPMu
mtx.Lock()
results[ns][podname] = r
mtx.Unlock()
}(r.SourceNs, r.SourcePod, (*requests).Sources[idx])
}(srcKey, dstKey, (*requests).Sources[idx])
}
wg.Wait()

Expand Down
46 changes: 46 additions & 0 deletions tests/e2e/e2e_trafficsplit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ var _ = DescribeTier1("Test HTTP from N Clients deployments to 1 Server deployme
_, err = td.CreateTrafficSplit(serverNamespace, tSplit)
Expect(err).To(BeNil())

By("Issuing http requests from clients to the traffic split FQDN")

// Test traffic
// Create Multiple HTTP request structure
requests := HTTPMultipleRequest{
Expand Down Expand Up @@ -239,6 +241,50 @@ var _ = DescribeTier1("Test HTTP from N Clients deployments to 1 Server deployme
}, 5, 150*time.Second)

Expect(success).To(BeTrue())

By("Issuing http requests from clients to the allowed individual service backends")

// Test now against the individual services, observe they should still be reachable
requests = HTTPMultipleRequest{
Sources: []HTTPRequestDef{},
}
for _, clientNs := range clientServices {
pods, err := td.client.CoreV1().Pods(clientNs).List(context.Background(), metav1.ListOptions{})
Expect(err).To(BeNil())
// For each client pod
for _, pod := range pods.Items {
// reach each service
for _, svcNs := range serverServices {
requests.Sources = append(requests.Sources, HTTPRequestDef{
SourceNs: pod.Namespace,
SourcePod: pod.Name,
SourceContainer: pod.Namespace, // We generally code it like so for test purposes

// direct traffic target against the specific server service in the server namespace
Destination: fmt.Sprintf("%s.%s", svcNs, serverNamespace),
})
}
}
}

results = HTTPMultipleResults{}
success = td.WaitForRepeatedSuccess(func() bool {
// Get results
results = td.MultipleHTTPRequest(&requests)

// Print results
td.PrettyPrintHTTPResults(&results)

// Verify REST status code results
for _, ns := range results {
for _, podResult := range ns {
if podResult.Err != nil || podResult.StatusCode != 200 {
return false
}
}
}
return true
}, 2, 150*time.Second)
})
})
})

0 comments on commit 7092567

Please sign in to comment.