Skip to content

Commit b558f8f

Browse files
authored
fix(conformance): change InferencePoolInvalidEPPService test to align with spec . (#1061)
* make InferencePoolInvalidEPPService stick to the API spec. * reinfe api and test case. * revert api change to make this PR forcus on conformance test. * use invalid pool.
1 parent 2ae867d commit b558f8f

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

conformance/tests/basic/inferencepool_invalid_epp_service.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ limitations under the License.
1717
package basic
1818

1919
import (
20-
"net/http"
2120
"testing"
2221

2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
"k8s.io/apimachinery/pkg/types"
24+
inferenceapi "sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
2525
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
2626
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2727
"sigs.k8s.io/gateway-api/pkg/features"
2828

2929
"sigs.k8s.io/gateway-api-inference-extension/conformance/tests"
30-
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
31-
conformancehttp "sigs.k8s.io/gateway-api/conformance/utils/http"
30+
k8sutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/kubernetes"
31+
trafficutils "sigs.k8s.io/gateway-api-inference-extension/conformance/utils/traffic"
3232
)
3333

3434
func init() {
@@ -49,30 +49,27 @@ var InferencePoolInvalidEPPService = suite.ConformanceTest{
4949
routePath = "/invalid-epp-test"
5050
infraNamespace = "gateway-conformance-infra"
5151
appNamespace = "gateway-conformance-app-backend"
52+
poolName = "pool-with-invalid-epp"
5253
)
5354

5455
routeNN := types.NamespacedName{Name: "httproute-for-invalid-epp-pool", Namespace: appNamespace}
5556
gwNN := types.NamespacedName{Name: "conformance-primary-gateway", Namespace: infraNamespace}
57+
poolNN := types.NamespacedName{Name: poolName, Namespace: appNamespace}
5658

5759
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, s.Client, s.TimeoutConfig, s.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
58-
59-
t.Run("HTTPRoute has a ResolvedRefs Condition with status False and Reason BackendNotFound", func(t *testing.T) {
60-
resolvedRefsCond := metav1.Condition{
61-
Type: string(gatewayv1.RouteConditionResolvedRefs),
60+
t.Run("InferecePool has a ResolvedRefs Condition with status False", func(t *testing.T) {
61+
acceptedCondition := metav1.Condition{
62+
Type: string(inferenceapi.InferencePoolConditionResolvedRefs), // Standard condition type
6263
Status: metav1.ConditionFalse,
63-
Reason: string(gatewayv1.RouteReasonBackendNotFound),
64+
Reason: "", // "" means we don't strictly check the Reason for this basic test.
6465
}
65-
kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gwNN, resolvedRefsCond)
66+
k8sutils.InferencePoolMustHaveCondition(t, s.Client, poolNN, acceptedCondition)
6667
})
6768

6869
t.Run("Request to a route with an invalid backend reference receives a 500 response", func(t *testing.T) {
69-
conformancehttp.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, conformancehttp.ExpectedResponse{
70-
Request: conformancehttp.Request{
71-
Path: routePath,
72-
},
73-
Response: conformancehttp.Response{
74-
StatusCode: http.StatusInternalServerError,
75-
},
70+
trafficutils.MakeRequestAndExpectEventuallyConsistentResponse(t, s.RoundTripper, s.TimeoutConfig, gwAddr, trafficutils.Request{
71+
Path: routePath,
72+
ExpectedStatusCode: 5, // Expecting response status code 5XX.
7673
})
7774
})
7875
},

conformance/tests/basic/inferencepool_invalid_epp_service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: gateway-conformance-app-backend
66
spec:
77
selector:
8-
app: "inference-model-1"
8+
app: primary-inference-model-server
99
targetPortNumber: 3000
1010
extensionRef:
1111
name: non-existent-epp-svc

conformance/utils/config/timing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type InferenceExtensionTimeoutConfig struct {
4747
func DefaultInferenceExtensionTimeoutConfig() InferenceExtensionTimeoutConfig {
4848
config := gatewayconfig.DefaultTimeoutConfig()
4949
config.HTTPRouteMustHaveCondition = 300 * time.Second
50+
config.RouteMustHaveParents = 200 * time.Second
5051
config.MaxTimeToConsistency = 200 * time.Second
5152
config.DefaultTestTimeout = 600 * time.Second
5253
return InferenceExtensionTimeoutConfig{

conformance/utils/traffic/traffic.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func waitForConvergeToExpected(
159159
return false
160160
}
161161

162-
if err := gwhttp.CompareRequest(t, &request.Request, cReq, cRes, expectedResponse); err != nil {
162+
if err := CompareRequestWithWildcardStatus(t, &request.Request, cReq, cRes, expectedResponse); err != nil {
163163
tlog.Logf(t, "Response expectation failed for request: %+v not ready yet: %v (after %v)", request.Request, err, elapsed)
164164
return false
165165
}
@@ -169,6 +169,26 @@ func waitForConvergeToExpected(
169169
tlog.Logf(t, "Request passed")
170170
}
171171

172+
// CompareRequestWithWildcardStatus compares requests with wildcard status code support.
173+
// It treats a single-digit expected code (e.g., 4) as a class wildcard (4xx),
174+
// while standard 3-digit codes are matched exactly.
175+
func CompareRequestWithWildcardStatus(t *testing.T, req *roundtripper.Request, cReq *roundtripper.CapturedRequest, cRes *roundtripper.CapturedResponse, expected gwhttp.ExpectedResponse) error {
176+
if expected.Response.StatusCode < 1 || expected.Response.StatusCode >= 100 {
177+
return gwhttp.CompareRequest(t, req, cReq, cRes, expected)
178+
}
179+
180+
expectedClass := expected.Response.StatusCode
181+
actualClass := cRes.StatusCode / 100
182+
if expectedClass != actualClass {
183+
return fmt.Errorf("expected status code class %dxx, but got %d", expectedClass, cRes.StatusCode)
184+
}
185+
186+
// StatusCode Class matches; update status code on a copy to allow the standard comparator to pass.
187+
modifiedExpected := expected
188+
modifiedExpected.Response.StatusCode = cRes.StatusCode
189+
return gwhttp.CompareRequest(t, req, cReq, cRes, modifiedExpected)
190+
}
191+
172192
// TODO: https://github.com/kubernetes-sigs/gateway-api-inference-extension/issues/1031
173193
// remove this when sigs.k8s.io/gateway-api/conformance/utils/roundtripper is able to send request with body.
174194
// RequestWithBody extends roundtripper.Request to include a request body.

0 commit comments

Comments
 (0)