fixing undeterministic behavior in keepOriginalEncodingOfQueryParameter() #4004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Deflake keepOriginalEncodingOfQueryParameter by relaxing URI ordering assertion
While running the Spring Cloud Gateway MVC tests (including with tools like NonDex), I observed non-deterministic failures in
ProxyExchangeHandlerFunctionTest.keepOriginalEncodingOfQueryParameter().The original test asserted that the entire URI, including the precise ordering of query parameters, exactly matched a hard-coded value:
However, the order of query parameters is not guaranteed. When the iteration order of parameters changes (for example, under NonDex’s randomized iteration), the resulting URI may still contain exactly the same parameters and encodings
but in a different order. In that case, the hasToString assertion fails even though the behavior of ProxyExchangeHandlerFunction is correct.
This is a classic implementation-dependent (ID) flaky test pattern: the test is asserting on concrete implementation details (a specific parameter ordering) rather than the actual contract (preserving the encoded path and parameter values).
This PR updates the test to verify that the URI contains the expected path and query fragments independently of their order, while still asserting on the decoded path and parameter values:
Summary of changes
spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/handler/ProxyExchangeHandlerFunctionTest.java:
Before:
URI uri = proxyExchange.getRequest().getUri();
After: