Fix nondeterministic iteration order in Fix Nondeterministic Iteration Order in CommentNotificationEventListenerTest - #3
Open
LucaDai wants to merge 1 commit into
Conversation
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.
Fix nondeterministic iteration order in CommentNotificationEventListenerTest
Summary
This PR fixes a nondeterministic failure in
CommentNotificationEventListenerTest.The nonderterministic can reporduce by running command:
mvn -pl jbpm-case-mgmt/jbpm-case-mgmt-impl \ edu.illinois:nondex-maven-plugin:1.1.2:nondex \ -Dtest=org.jbpm.casemgmt.impl.event.CommentNotificationEventListenerTest#testNotificationOnCommentAddedWithRawBodyThe failure was caused by the use of a
HashMapinsideCommentNotificationEventListenerwhen building notification parameters. SinceHashMapdoes not guarantee iteration order, the generated user list sometimes appeared as[mary, john]and sometimes[john, mary]. The strict equality assertion in the test was sensitive to this order, leading to inconsistent results.Relevant code in
CommentNotificationEventListener:While
HashMapiteration order may appear stable in many runs, it is not guaranteed and can vary across JDK versions, platforms, or data sizes.Error Message from Nondex:
Fix
Replaced the strict isEqualTo assertion with a regex matches assertion that accepts both possible orderings while still validating correctness:
This ensures the test is resilient to nondeterministic iteration order but continues to check that both "john" and "mary" are present in the notification.
Verification
HashMap,HashSet,getDeclaredFields) so that nondeterministic behaviors hidden in normal runs can be exposed.HashMapiteration order produced[john, mary]instead of[mary, john].-DnondexRuns=20) under randomized orders, and all runs passed.Why this matters
Nondeterministic behavior may not surface in every run, but it introduces long-term risks for reliability and maintainability:
By making the test resilient to iteration order, we ensure stable, reproducible test results across environments and future JDK versions.
JIRA: N/A (class project / no ticket)
Referenced Pull Requests: N/A