Merge pull request #96966 from tkashem/pf-e2e

p&f e2e: the test should log expected and actual response header in case it fails.
This commit is contained in:
Kubernetes Prow Robot 2021-01-08 07:56:56 -08:00 committed by GitHub
commit b259c92dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,26 +45,37 @@ const (
var _ = SIGDescribe("API priority and fairness", func() { var _ = SIGDescribe("API priority and fairness", func() {
f := framework.NewDefaultFramework("apf") f := framework.NewDefaultFramework("apf")
ginkgo.It("should ensure that requests can be classified by testing flow-schemas/priority-levels", func() { ginkgo.It("should ensure that requests can be classified by adding FlowSchema and PriorityLevelConfiguration", func() {
testingFlowSchemaName := "e2e-testing-flowschema" testingFlowSchemaName := "e2e-testing-flowschema"
testingPriorityLevelName := "e2e-testing-prioritylevel" testingPriorityLevelName := "e2e-testing-prioritylevel"
matchingUsername := "noxu" matchingUsername := "noxu"
nonMatchingUsername := "foo" nonMatchingUsername := "foo"
ginkgo.By("creating a testing prioritylevel") ginkgo.By("creating a testing PriorityLevelConfiguration object")
createdPriorityLevel, cleanup := createPriorityLevel(f, testingPriorityLevelName, 1) createdPriorityLevel, cleanup := createPriorityLevel(f, testingPriorityLevelName, 1)
defer cleanup() defer cleanup()
ginkgo.By("creating a testing flowschema") ginkgo.By("creating a testing FlowSchema object")
createdFlowSchema, cleanup := createFlowSchema(f, testingFlowSchemaName, 1000, testingPriorityLevelName, []string{matchingUsername}) createdFlowSchema, cleanup := createFlowSchema(f, testingFlowSchemaName, 1000, testingPriorityLevelName, []string{matchingUsername})
defer cleanup() defer cleanup()
ginkgo.By("checking response headers contain flow-schema/priority-level uid") var response *http.Response
if !testResponseHeaderMatches(f, matchingUsername, string(createdPriorityLevel.UID), string(createdFlowSchema.UID)) { ginkgo.By("response headers should contain the UID of the appropriate FlowSchema and PriorityLevelConfiguration for a matching user")
framework.Failf("matching user doesnt received UID for the testing priority-level and flow-schema") response = makeRequest(f, matchingUsername)
if plUIDWant, plUIDGot := string(createdPriorityLevel.UID), getPriorityLevelUID(response); plUIDWant != plUIDGot {
framework.Failf("expected PriorityLevelConfiguration UID in the response header: %s, but got: %s, response header: %#v", plUIDWant, plUIDGot, response.Header)
} }
if testResponseHeaderMatches(f, nonMatchingUsername, string(createdPriorityLevel.UID), string(createdPriorityLevel.UID)) { if fsUIDWant, fsUIDGot := string(createdFlowSchema.UID), getFlowSchemaUID(response); fsUIDWant != fsUIDGot {
framework.Failf("non-matching user unexpectedly received UID for the testing priority-level and flow-schema") framework.Failf("expected FlowSchema UID in the response header: %s, but got: %s, response header: %#v", fsUIDWant, fsUIDGot, response.Header)
}
ginkgo.By("response headers should contain non-empty UID of FlowSchema and PriorityLevelConfiguration for a non-matching user")
response = makeRequest(f, nonMatchingUsername)
if plUIDGot := getPriorityLevelUID(response); plUIDGot == "" {
framework.Failf("expected a non-empty PriorityLevelConfiguration UID in the response header, but got: %s, response header: %#v", plUIDGot, response.Header)
}
if fsUIDGot := getFlowSchemaUID(response); fsUIDGot == "" {
framework.Failf("expected a non-empty FlowSchema UID in the response header but got: %s, response header: %#v", fsUIDGot, response.Header)
} }
}) })
@ -341,15 +352,12 @@ func makeRequest(f *framework.Framework, username string) *http.Response {
return response return response
} }
func testResponseHeaderMatches(f *framework.Framework, impersonatingUser, plUID, fsUID string) bool { func getPriorityLevelUID(response *http.Response) string {
response := makeRequest(f, impersonatingUser) return response.Header.Get(flowcontrol.ResponseHeaderMatchedPriorityLevelConfigurationUID)
if response.Header.Get(flowcontrol.ResponseHeaderMatchedFlowSchemaUID) != fsUID { }
return false
} func getFlowSchemaUID(response *http.Response) string {
if response.Header.Get(flowcontrol.ResponseHeaderMatchedPriorityLevelConfigurationUID) != plUID { return response.Header.Get(flowcontrol.ResponseHeaderMatchedFlowSchemaUID)
return false
}
return true
} }
// uniformQPSLoadSingle loads the API server with requests at a uniform <qps> // uniformQPSLoadSingle loads the API server with requests at a uniform <qps>