-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweaks around accessing SuiteResult #3099
Conversation
WalkthroughThe modifications in Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- testng-core/src/main/java/org/testng/SuiteRunner.java (2 hunks)
Additional comments: 2
testng-core/src/main/java/org/testng/SuiteRunner.java (2)
- 423-423: The removal of lock-based synchronization around
suiteResults
and the direct insertion intosuiteResults
here assumes thatrunTest
is always called in a thread-safe manner. Given thatSuiteRunner
may execute tests in parallel, it's crucial to ensure that all modifications tosuiteResults
are thread-safe. The use ofCollections.synchronizedMap
forsuiteResults
does provide thread safety for the map itself, but iterating over the map or performing compound actions still requires external synchronization to avoid concurrent modification exceptions or other thread safety issues.Ensure that all access patterns to
suiteResults
are safe and consider if additional synchronization is needed when iterating over or performing compound actions onsuiteResults
.
- 513-518: The change to return an
UnmodifiableMap
wrapped around a newLinkedHashMap
instance ofsuiteResults
in thegetResults
method is a good practice to prevent unintended modifications by the consumers of this method. However, it's important to note that while this prevents modifications to the map itself, it does not prevent modifications to the objects contained within the map. IfISuiteResult
objects are mutable, consumers could still alter their state, potentially leading to inconsistencies.Consider documenting the expected immutability of the
ISuiteResult
objects or ensuring that they are deeply immutable if necessary to maintain the integrity of the suite results.
// to enter and exit the synchronized block. | ||
// Also just to ensure that we guard the internals of the suite results we now wrap it | ||
// around with an unmodifiable map. | ||
return Collections.unmodifiableMap(new LinkedHashMap<>(suiteResults)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create a new intermediate map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are returning back a new map, because suiteResults
is a synchronizedMap which means there's an added cost to entering/exiting the mutex barrier created by the synchronized
block within the get
operation of the SynchronizedMap
.
Closes testng-team#3078 Following changes were made: * Removed the lock based synchronization around SuiteResult because it’s already backed by a SynchronizedMap from Collections. * Altered the getter such that it returns back a regular linkedHashMap (without the synchronisation Because users are expected ONLY to iterate on it and NOT change its state) * Also just to ensure that users don’t garble the Suite result, wrapping it with an UnModifiableMap
d394472
to
ac2bc22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- testng-core/src/main/java/org/testng/SuiteRunner.java (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- testng-core/src/main/java/org/testng/SuiteRunner.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check that all map usages are synchronised?
This map is being written into in only one place. And that place is already guarded by an I think for concurrent reads we don't need to have any synchronization. Only when a read and write happens together on a collection is when it would throw a |
Closes #3078
Following changes were made:
SynchronizedMap from Collections.
Fixes #3078 .
Summary by CodeRabbit