[#4966] Fixing flaky test UnitTestSwaggerUtils#testSwagger
#4967
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.
Issue
The method
testSwagger ()inUnitTestSwaggerUtilsfrom moduleswagger/swagger-generator/generator-corecompares pretty-printed YAML strings to verify correctness. However, since the OpenAPI object is constructed withMap/Setiteration, the key order in the serialized YAML is non-deterministic. When the iteration order changes, the string comparison fails, resulting in flaky behavior.This test was flagged by the NonDex tool, which detects unreliable tests caused by hidden assumptions in Java API ordering. To reproduce, run an upper test that calls
testSwagger, for example:Affected Tests
This change fixes the below tests:
org.apache.servicecomb.swagger.generator.core.TestPojo.testResponseEntityorg.apache.servicecomb.swagger.generator.core.TestSwaggerUtils.testSchemaMethodorg.apache.servicecomb.swagger.generator.core.TestPojoExample.testPojoExample1Fix
Instead of checking raw YAML string equality, I used
JSONAssert.assertEquals()to compare them structurally. This makes the test order-insensitive and removes the non-determinism.Rerunning NonDex with this change shows a stable passing result.
PR Checklist
UnitTestSwaggerUtils#testSwagger(#4966 )mvn clean install -Pitto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.[SCB-XXX] Fix flaky test in TestSwaggerUtils#testSchemaMethod, where you replaceSCB-XXXwith the appropriate JIRA issue.