[fix][test] Fixed Nondeterministic Ordering in Generated Docs Topics#24973
Merged
lhotari merged 1 commit intoapache:masterfrom Nov 11, 2025
Merged
[fix][test] Fixed Nondeterministic Ordering in Generated Docs Topics#24973lhotari merged 1 commit intoapache:masterfrom
lhotari merged 1 commit intoapache:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24973 +/- ##
=============================================
+ Coverage 38.77% 74.23% +35.46%
- Complexity 13380 33997 +20617
=============================================
Files 1856 1920 +64
Lines 145342 150146 +4804
Branches 16886 17414 +528
=============================================
+ Hits 56353 111459 +55106
+ Misses 81459 29783 -51676
- Partials 7530 8904 +1374
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
lhotari
approved these changes
Nov 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #24968
Motivation
The below test compares the generated documentation of
CmdGenerateDocsTest#testGenerateDocs. The test assumes a deterministic order of the generated documentation but the order of the listedhelpandnameoptions was not guaranteed. Due to two sources of nondeterminism hidden in the test and production code, the options could be listed in a different order. Picocli'sCommandLineclass uses Class#getDeclaredFields internally (via reflection), which has a non-deterministic specification to retrieve theOptionannotations and orders these options accordingly. Even though picocli supports an order attribute onOptionannotations, CommandLine never sorts by this order - it just maintains whatever order the reflection API gave it.CmdGenerateDocs#generateDocumentthen iterates over the order that theargsmethod returns, with the assumption that the order is deterministic. Unfortunately, the ordering can change due to different environments producing the contents in different orders despite the logical contents being the same. Harmless re-ordering could flip the tests from pass to fail despite the data being semantically the same.org.apache.pulsar.docs.tools.CmdGenerateDocsTest.testGenerateDocsModifications
The order of each option in the Argument class is now explicitly stated so
getDeclaredFieldsis no longer utilized to determine the order of the options. Additionally,generateDocumentnow sorts allargSpecsby their specified order with a new helper method calledgetSortedArgs. This combination of changes enforces the expected nondeterminism in the ordering of the listed options.If order is not specified because it does not matter, the order for each option will remain in it's original order as before. This is because according to Collection's documentation, it's sort method is guaranteed to be stable: equal elements will not be reordered as a result of the sort (and the orders are equal because Piccocli's
CommandLineclass sets order to -1 by default).Verifying this change
This change is already covered by existing tests, such as
org.apache.pulsar.client.impl.schema.SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValueorg.apache.pulsar.client.impl.schema.SchemaInfoTest.testSchemaInfoToStringDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: LucasEby#8