Skip to content

Conversation

@pem70
Copy link
Contributor

@pem70 pem70 commented Oct 1, 2025

Issue

The method testSwagger () in UnitTestSwaggerUtils from module swagger/swagger-generator/generator-core compares pretty-printed YAML strings to verify correctness. However, since the OpenAPI object is constructed with Map/Set iteration, 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:

mvn -pl swagger/swagger-generator/generator-core   edu.illinois:nondex-maven-plugin:2.1.7:nondex   -Dtest=org.apache.servicecomb.swagger.generator.core.TestSwaggerUtils#testSchemaMethod

Affected Tests

This change fixes the below tests:
org.apache.servicecomb.swagger.generator.core.TestPojo.testResponseEntity
org.apache.servicecomb.swagger.generator.core.TestSwaggerUtils.testSchemaMethod
org.apache.servicecomb.swagger.generator.core.TestPojoExample.testPojoExample1

Fix

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

  • Github Issue: [BUG] - Flaky test in UnitTestSwaggerUtils#testSwagger (#4966 )
  • Each commit in the pull request should have a meaningful subject line and body.
  • Run mvn clean install -Pit to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • Format the pull request title like [SCB-XXX] Fix flaky test in TestSwaggerUtils#testSchemaMethod, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.

@pem70 pem70 marked this pull request as ready for review October 1, 2025 19:24
@pem70 pem70 changed the title [#4966] Fixing flaky test TestSwaggerUtils#testSchemaMethod [#4966] Fixing flaky test UnitTestSwaggerUtils#testSwagger Oct 1, 2025
@pem70 pem70 force-pushed the fix-testSchemaMethod branch from 0fbe2a6 to f4734f7 Compare October 1, 2025 22:33
@pem70 pem70 marked this pull request as draft October 2, 2025 02:28
@pem70 pem70 marked this pull request as ready for review October 2, 2025 02:37
@liubao68
Copy link
Contributor

Sorry I will not merge this pull request as I do not want to introduce new dependencies for runtime package.
This is a historical problem to add test code in runtime component, and will take a bit effort to fix it.

@pem70
Copy link
Contributor Author

pem70 commented Oct 20, 2025

Sorry I will not merge this pull request as I do not want to introduce new dependencies for runtime package. This is a historical problem to add test code in runtime component, and will take a bit effort to fix it.

Thanks for your feedback! I opened a new PR, which addressed the same issue without introducing new dependencies. It would be great if you could have a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants