Skip to content

Commit d394472

Browse files
committed
Tweaks around accessing SuiteResult
Closes #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
1 parent 69dc232 commit d394472

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

testng-core/src/main/java/org/testng/SuiteRunner.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,12 @@ private void runSequentially() {
415415
}
416416
}
417417

418-
private final AutoCloseableLock suiteResultsLock = new AutoCloseableLock();
419-
420418
private void runTest(TestRunner tr) {
421419
visualisers.forEach(tr::addListener);
422420
tr.run();
423421

424422
ISuiteResult sr = new SuiteResult(xmlSuite, tr);
425-
try (AutoCloseableLock ignore = suiteResultsLock.lock()) {
426-
suiteResults.put(tr.getName(), sr);
427-
}
423+
suiteResults.put(tr.getName(), sr);
428424
}
429425

430426
/**
@@ -514,7 +510,12 @@ public String getOutputDirectory() {
514510

515511
@Override
516512
public Map<String, ISuiteResult> getResults() {
517-
return suiteResults;
513+
// When users want to access the results, they are NOT expected to alter it's state.
514+
// So we don't need to be sending back a synchronized map which adds a small additional cost
515+
// to enter and exit the synchronized block.
516+
// Also just to ensure that we guard the internals of the suite results we now wrap it
517+
// around with an unmodifiable map.
518+
return Collections.unmodifiableMap(new LinkedHashMap<>(suiteResults));
518519
}
519520

520521
/**

0 commit comments

Comments
 (0)