@@ -17,18 +17,22 @@ limitations under the License.
1717package basic
1818
1919import (
20+ "fmt"
2021 "net/http"
22+ "slices"
2123 "strings"
2224 "testing"
2325
2426 "github.com/stretchr/testify/require"
27+ "golang.org/x/sync/errgroup"
2528 "k8s.io/apimachinery/pkg/types"
2629 "sigs.k8s.io/gateway-api/conformance/utils/suite"
2730 "sigs.k8s.io/gateway-api/pkg/features"
2831
2932 "sigs.k8s.io/gateway-api-inference-extension/conformance/tests"
3033 k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
3134 "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
35+ trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3236 gwhttp "sigs.k8s.io/gateway-api/conformance/utils/http"
3337)
3438
@@ -88,12 +92,14 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
8892 }`
8993
9094 for i := 0 ; i < len (pods ); i ++ {
91- traffic .MakeRequestWithRequestParamAndExpectSuccess (
95+ // Send an initial request targeting a single pod and wait for it to be successful to ensure the Gateway and EPP
96+ // are functioning correctly before running the main test cases.
97+ trafficutils .MakeRequestWithRequestParamAndExpectSuccess (
9298 t ,
9399 s .RoundTripper ,
94100 s .TimeoutConfig ,
95101 gwAddr ,
96- traffic .Request {
102+ trafficutils .Request {
97103 Host : hostname ,
98104 Path : path ,
99105 Headers : map [string ]string {eppSelectionHeaderName : podIPs [i ]},
@@ -135,7 +141,7 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
135141 t .Logf ("Sending request to %s with EPP header '%s: %s'" , gwAddr , eppSelectionHeaderName , eppHeaderValue )
136142 t .Logf ("Expecting traffic to be routed to pod: %v" , tc .expectAllRequestsRoutedWithinPodNames )
137143
138- traffic . AssertTrafficOnlyReachesToExpectedPods (t , s . RoundTripper , gwAddr , gwhttp.ExpectedResponse {
144+ assertTrafficOnlyReachesToExpectedPods (t , s , gwAddr , gwhttp.ExpectedResponse {
139145 Request : gwhttp.Request {
140146 Host : hostname ,
141147 Path : path ,
@@ -152,3 +158,37 @@ var GatewayFollowingEPPRouting = suite.ConformanceTest{
152158 }
153159 },
154160}
161+
162+ func assertTrafficOnlyReachesToExpectedPods (t * testing.T , suite * suite.ConformanceTestSuite , gwAddr string , expected gwhttp.ExpectedResponse , requestBody string , expectedPodNames []string ) {
163+ t .Helper ()
164+ const (
165+ concurrentRequests = 10
166+ totalRequests = 100
167+ )
168+ var (
169+ roundTripper = suite .RoundTripper
170+ g errgroup.Group
171+ req = gwhttp .MakeRequest (t , & expected , gwAddr , "HTTP" , "http" )
172+ )
173+ g .SetLimit (concurrentRequests )
174+ for i := 0 ; i < totalRequests ; i ++ {
175+ g .Go (func () error {
176+ cReq , cRes , err := traffic .MakeCallRoundTripper (t , roundTripper , & traffic.RequestWithBody {Request : req , Body : strings .NewReader (requestBody )})
177+ if err != nil {
178+ return fmt .Errorf ("failed to roundtrip request: %w" , err )
179+ }
180+ if err := gwhttp .CompareRequest (t , & req , cReq , cRes , expected ); err != nil {
181+ return fmt .Errorf ("response expectation failed for request: %w" , err )
182+ }
183+
184+ if slices .Contains (expectedPodNames , cReq .Pod ) {
185+ return nil
186+ }
187+ return fmt .Errorf ("request was handled by an unexpected pod %q" , cReq .Pod )
188+ })
189+ }
190+ if err := g .Wait (); err != nil {
191+ t .Fatalf ("Not all the requests are sent to the expectedPods successfully, err: %v" , err )
192+ }
193+ t .Logf ("Traffic successfully reached only to expected pods: %v" , expectedPodNames )
194+ }
0 commit comments