Fixing undeterministic behavior from rewriteRequestParameterWithEncodedRemainParameters() test #4003
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 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:
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:
Summary of changes
spring-cloud-gateway-server-webmvc/src/test/java/org/springframework/cloud/gateway/server/mvc/filter/BeforeFilterFunctionsTests.java:
Before:
After:
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.