Skip to content

Conversation

@rjuare8
Copy link
Contributor

@rjuare8 rjuare8 commented Nov 30, 2025

Deflake rewriteEncodedRequestParameter by relaxing URI ordering assertion

While running the Spring Cloud Gateway MVC tests with NonDex, I observed non-deterministic failures in BeforeFilterFunctionsTests.rewriteEncodedRequestParameter().

The original test asserted that the entire URI string, including query parameters and their ordering, exactly matched a hard-coded value:

assertThat(result.uri().toString())
    .hasToString("http://localhost/path?quux=corge%2B&baz=qux&foo%5B%5D=replacement%5B%5D");

However, the order of query parameters is not guaranteed. NonDex randomizes iteration order to surface this kind of order-dependence. Under some executions, the URI contained the same parameters and encodings, but in a different order, causing the hasToString assertion to fail even though the behavior was correct.

NonDex classifies this as an ID (implementation-dependent) flaky test:
the failure comes from the test relying on implementation-specific details (a particular parameter ordering) that are not part of the API contract.

This PR updates the test to verify that the URI contains the expected path and query fragments independently of their order:

assertThat(result.uri().toString())
    .contains(
        "http://localhost/path?",
        "quux=corge%2B",
        "baz=qux",
        "foo%5B%5D=replacement%5B%5D"
    );

Summary of changes
spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/BeforeFilterFunctionsTests.java:

Before:

assertThat(result.uri().toString())
    .hasToString("http://localhost/path?quux=corge%2B&baz=qux&foo%5B%5D=replacement%5B%5D");

After:

assertThat(result.uri().toString())
    .contains(
        "http://localhost/path?",
        "quux=corge%2B",
        "baz=qux",
        "foo%5B%5D=replacement%5B%5D"
    );

Motivation
With NonDex enabled, rewriteEncodedRequestParameter would sometimes fail solely because the query parameter ordering in the resulting URI differed from the hard-coded string, despite all parameters being present and correctly encoded.

…edRemainParameters() test

Signed-off-by: Rodolfo Juarez <[email protected]>
@raccoonback
Copy link
Contributor

Good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants