-
Notifications
You must be signed in to change notification settings - Fork 828
Description
Steps to Reproduce
The method testSwagger in UnitTestSwaggerUtils from module swagger/swagger-generator/generator-core compares pretty-printed YAML strings or arrays to verify correctness. However, since YAML serialization relies on iteration order of Map/Set, the key order in the output can vary. This test uses a hard-coded YAML string as the expected value, but the test fails intermittently if the keys are emitted in a different order than expected.
This test was flagged via the NonDex tool, which detects potentially unreliable tests caused by hidden assumptions in Java API ordering. To see the NonDex output for this test, you can run NonDex on an upper test that calls this test, for example, onTestSwaggerUtils#testSchemaMethod:
mvn -pl swagger/swagger-generator/generator-core edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=org.apache.servicecomb.swagger.generator.core.TestSwaggerUtils#testSchemaMethodExpected Behavior
The test should consistently pass, regardless of key ordering in the serialized YAML.
Servicecomb Version
3.3.0
Additional Context
I have prepared a fix in a pull request. The approach parses both expected and actual YAML into JSON trees and compares them structurally, eliminating the ordering issue. I’ll be adding that PR to the discussion.