Skip to content

Commit

Permalink
Fixing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
krmahadevan committed Feb 26, 2024
1 parent 02132bd commit 9d0ba52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -848,14 +848,14 @@ public ITestResult registerSkippedTestResult(
return result;
}

private static final AutoCloseableLock LOCK = new AutoCloseableLock();
private static final AutoCloseableLock internalLock = new AutoCloseableLock();

private StatusHolder considerExceptions(
ITestNGMethod tm,
ITestResult testResult,
ExpectedExceptionsHolder exceptionsHolder,
FailureContext failure) {
try (AutoCloseableLock ignore = LOCK.lock()) {
try (AutoCloseableLock ignore = internalLock.lock()) {
return considerExceptionsInternal(tm, testResult, exceptionsHolder, failure);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package test.listeners.factory;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.testng.IExecutionListener;

public class ExampleListener implements IExecutionListener {

public static ExampleListener instance;

private static final AtomicBoolean once = new AtomicBoolean(false);
private static final AtomicReference<ExampleListener> instance = new AtomicReference<>();

public ExampleListener() {
setInstance(this);
}

private static void setInstance(ExampleListener instance) {
if (once.compareAndSet(false, true)) {
if (ExampleListener.instance == null) {
ExampleListener.instance = instance;
}
}
ExampleListener.instance.compareAndSet(null, instance);
}

public static ExampleListener getInstance() {
return instance.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testListenerFactoryViaConfigurationArg() {
};
TestNG testng = TestNG.privateMain(args, null);
assertThat(SampleTestFactory.instance).isNotNull();
assertThat(ExampleListener.instance).isNotNull();
assertThat(ExampleListener.getInstance()).isNotNull();
assertThat(testng.getStatus()).isZero();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ public void test3Threads() {
test(3);
}

private final KeyAwareAutoCloseableLock lock = new KeyAwareAutoCloseableLock();

private void test(int threadCount) {
Helper.reset();
MultiThreadedDependentSampleTest.m_methods = Lists.newArrayList();
TestNG tng = create(MultiThreadedDependentSampleTest.class);
tng.setThreadCount(threadCount);
tng.setParallel(XmlSuite.ParallelMode.METHODS);
Map<Long, Long> map = Helper.getMap(MultiThreadedDependentSampleTest.class.getName());
KeyAwareAutoCloseableLock lock = new KeyAwareAutoCloseableLock();
try (KeyAwareAutoCloseableLock.AutoReleasable ignore = lock.lockForObject(map)) {
tng.run();
Assert.assertTrue(map.size() > 1, "Map size:" + map.size() + " expected more than 1");
Expand Down

0 comments on commit 9d0ba52

Please sign in to comment.