Fix nondeterministic failures in HttpOperationsTest #1778
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.
Description
Type of change
Summary
The flaky behavior was detected in org.zalando.riptide.compatibility.HttpOperationsTest#shouldPut when running under NonDex randomization, which revealed that the test relied on deterministic field ordering in the serialized JSON request body.
Example of the original test assertion:
verifyRequestBody(recordedRequest, "{\"name\":\"D. Fault\",\"birthday\":\"1984-09-13\"}");However, the JSON serialization of request bodies can vary in key ordering depending on the underlying Map or serializer implementation used within Jackson.
Since JSON field order is not guaranteed by the specification, different JVM runs or environments may produce:
The helper method verifyRequestBody(...) was asserting equality on raw JSON strings:
assertEquals(expectedBody, recordedRequest.getBody().readString(UTF_8));
This made the test order-sensitive to the serialization order of JSON fields, even though the semantic data was identical.
Failure Message running NonDex:
Fix
The test verification was updated to perform semantic comparison instead of string equality:
• Both the expected and actual JSON strings are parsed into maps using Jackson’s ObjectMapper.readValue().
• The test now asserts equality on these parsed Map<String, String> objects, which ignores field order differences.
• The content type check (application/json) remains intact to preserve original behavior.
Updated code excerpt:
This ensures deterministic, logically equivalent test validation across environments and JVMs, eliminating the order-dependent flaky behavior.
Related Tests
How to Reproduce
Reproduced the failure using NonDex, a tool from the University of Illinois designed to detect ID tests (Iteration-Dependent tests).
Build module and Run a single test (no shuffling)
All tests pass.
Run with NonDex (shuffling)
cd riptide-compatibility mvn -T1 edu.illinois:nondex-maven-plugin:2.2.1:nondex \ -Denforcer.skip=true \ -Dtest=org.zalando.riptide.compatibility.HttpOperationsTest \ -DnondexRuns=10 \ -DnondexMode=FULL \ -DfailIfNoTests=false \ -Dmaven.test.failure.ignore=trueExpected Example
Verification
-DnondexRuns=100) pass with no flakes.