Skip to content

Commit

Permalink
fix: add retries to ext-proc tests (#3641)
Browse files Browse the repository at this point in the history
use converging assertion

Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc authored Jun 24, 2024
1 parent 258eecd commit 9830c4d
Showing 1 changed file with 34 additions and 46 deletions.
80 changes: 34 additions & 46 deletions test/e2e/tests/ext_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ var ExtProcTest = suite.ConformanceTest{
Host: "www.example.com",
Path: "/processor",
Headers: map[string]string{
"x-request-ext-processed": "true", // header added by ext-processor to backend-bound request
"x-request-client-header-received": "original", // this is the original client header preserved by ext-proc in a new header
"x-request-client-header": "mutated", // this is the mutated value expected to reach upstream
"x-request-client-header": "original", // add a request header that will be mutated by ext-proc
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/processor",
Headers: map[string]string{
"x-request-ext-processed": "true", // header added by ext-processor to backend-bound request
"x-request-client-header-received": "original", // this is the original client header preserved by ext-proc in a new header
"x-request-client-header": "mutated", // this is the mutated value expected to reach upstream
},
},
},
Response: http.Response{
Expand All @@ -70,19 +78,7 @@ var ExtProcTest = suite.ConformanceTest{
Namespace: ns,
}

req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http")

// add a request header that will be mutated by ext-proc
req.Headers["x-request-client-header"] = []string{"original"}

cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req)
if err != nil {
t.Errorf("failed to get expected response: %v", err)
}

if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil {
t.Errorf("failed to compare request and response: %v", err)
}
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})

t.Run("http route without proc mode", func(t *testing.T) {
Expand All @@ -109,7 +105,15 @@ var ExtProcTest = suite.ConformanceTest{
Host: "www.example.com",
Path: "/no-processor",
Headers: map[string]string{
"x-request-client-header": "original",
"x-request-client-header": "original", // add a request header that will be mutated by ext-proc
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/no-processor",
Headers: map[string]string{
"x-request-client-header": "original", // this is the original value expected to reach upstream
},
},
},
Response: http.Response{
Expand All @@ -119,19 +123,7 @@ var ExtProcTest = suite.ConformanceTest{
Namespace: ns,
}

req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http")

// add a request header that will be mutated by ext-proc if the request headers are sent
req.Headers["x-request-client-header"] = []string{"original"}

cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req)
if err != nil {
t.Errorf("failed to get expected response: %v", err)
}

if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil {
t.Errorf("failed to compare request and response: %v", err)
}
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})

t.Run("http route with uds ext proc", func(t *testing.T) {
Expand All @@ -158,9 +150,17 @@ var ExtProcTest = suite.ConformanceTest{
Host: "www.example.com",
Path: "/uds-processor",
Headers: map[string]string{
"x-request-ext-processed": "true", // header added by ext-processor to backend-bound request
"x-request-client-header-received": "original", // this is the original client header preserved by ext-proc in a new header
"x-request-client-header": "mutated", // this is the mutated value expected to reach upstream
"x-request-client-header": "original", // add a request header that will be mutated by ext-proc
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/uds-processor",
Headers: map[string]string{
"x-request-ext-processed": "true", // header added by ext-processor to backend-bound request
"x-request-client-header-received": "original", // this is the original client header preserved by ext-proc in a new header
"x-request-client-header": "mutated", // this is the mutated value expected to reach upstream
},
},
},
Response: http.Response{
Expand All @@ -172,19 +172,7 @@ var ExtProcTest = suite.ConformanceTest{
Namespace: ns,
}

req := http.MakeRequest(t, &expectedResponse, gwAddr, "HTTP", "http")

// add a request header that will be mutated by ext-proc
req.Headers["x-request-client-header"] = []string{"original"}

cReq, cResp, err := suite.RoundTripper.CaptureRoundTrip(req)
if err != nil {
t.Errorf("failed to get expected response: %v", err)
}

if err := http.CompareRequest(t, &req, cReq, cResp, expectedResponse); err != nil {
t.Errorf("failed to compare request and response: %v", err)
}
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, expectedResponse)
})
},
}

0 comments on commit 9830c4d

Please sign in to comment.