Skip to content

Commit

Permalink
Tweaks around accessing SuiteResult
Browse files Browse the repository at this point in the history
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
  • Loading branch information
krmahadevan committed Mar 21, 2024
1 parent 69dc232 commit d394472
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions testng-core/src/main/java/org/testng/SuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,12 @@ private void runSequentially() {
}
}

private final AutoCloseableLock suiteResultsLock = new AutoCloseableLock();

private void runTest(TestRunner tr) {
visualisers.forEach(tr::addListener);
tr.run();

ISuiteResult sr = new SuiteResult(xmlSuite, tr);
try (AutoCloseableLock ignore = suiteResultsLock.lock()) {
suiteResults.put(tr.getName(), sr);
}
suiteResults.put(tr.getName(), sr);
}

/**
Expand Down Expand Up @@ -514,7 +510,12 @@ public String getOutputDirectory() {

@Override
public Map<String, ISuiteResult> getResults() {
return suiteResults;
// When users want to access the results, they are NOT expected to alter it's state.
// So we don't need to be sending back a synchronized map which adds a small additional cost
// 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));
}

/**
Expand Down

0 comments on commit d394472

Please sign in to comment.