Skip to content

Commit

Permalink
Attempting to fix failures due to LCM/GCM flags
Browse files Browse the repository at this point in the history
  • Loading branch information
krmahadevan committed Mar 20, 2024
1 parent 69dc232 commit 0b09262
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 168 deletions.
173 changes: 56 additions & 117 deletions testng-core/src/test/java/test/listeners/ListenersTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IAlterSuiteListener;
import org.testng.ITestNGListener;
Expand All @@ -10,7 +9,6 @@ public class AlterSuiteListenerHolder {

public static final String[] EXPECTED_LOGS =
new String[] {"MasterOogway.alter", "MasterShifu.alter", "DragonWarrior.alter"};
public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = AlterSuiteListenerHolder.class.getName() + "$";

public static final List<ITestNGListener> ALL =
Expand All @@ -25,7 +23,7 @@ public class AlterSuiteListenerHolder {
public abstract static class KungFuWarrior implements IAlterSuiteListener {
@Override
public void alter(List<XmlSuite> suites) {
LOGS.add(getClass().getSimpleName() + ".alter");
LogContainer.instance.log(getClass().getSimpleName() + ".alter");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IClassListener;
import org.testng.ITestClass;
import org.testng.ITestNGListener;

public class ClassListenerHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = ClassListenerHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -37,12 +35,12 @@ public abstract static class KungFuWarrior implements IClassListener {

@Override
public void onBeforeClass(ITestClass testClass) {
LOGS.add(getClass().getSimpleName() + ".onBeforeClass");
LogContainer.instance.log(getClass().getSimpleName() + ".onBeforeClass");
}

@Override
public void onAfterClass(ITestClass testClass) {
LOGS.add(getClass().getSimpleName() + ".onAfterClass");
LogContainer.instance.log(getClass().getSimpleName() + ".onAfterClass");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IConfigurationListener;
import org.testng.ITestNGListener;
Expand All @@ -9,7 +8,6 @@

public class ConfigurationListenerHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = ConfigurationListenerHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -58,25 +56,25 @@ public abstract static class KungFuWarrior implements IConfigurationListener {

@Override
public void beforeConfiguration(ITestResult tr, ITestNGMethod tm) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName() + ".beforeConfiguration_" + tr.getMethod().getMethodName());
}

@Override
public void onConfigurationSuccess(ITestResult tr, ITestNGMethod tm) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName() + ".onConfigurationSuccess_" + tr.getMethod().getMethodName());
}

@Override
public void onConfigurationFailure(ITestResult tr, ITestNGMethod tm) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName() + ".onConfigurationFailure_" + tr.getMethod().getMethodName());
}

@Override
public void onConfigurationSkip(ITestResult tr, ITestNGMethod tm) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName() + ".onConfigurationSkip_" + tr.getMethod().getMethodName());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.testng.*;

public class DataProviderInterceptorHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = DataProviderInterceptorHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -39,7 +37,8 @@ public Iterator<Object[]> intercept(
IDataProviderMethod dp,
ITestNGMethod method,
ITestContext iTestContext) {
LOGS.add(getClass().getSimpleName() + ".intercept_" + dp.getMethod().getName());
LogContainer.instance.log(
getClass().getSimpleName() + ".intercept_" + dp.getMethod().getName());
return original;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IDataProviderListener;
import org.testng.IDataProviderMethod;
Expand All @@ -10,7 +9,6 @@

public class DataProviderListenerHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = DataProviderListenerHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -48,7 +46,7 @@ public abstract static class KungFuWarrior implements IDataProviderListener {
@Override
public void beforeDataProviderExecution(
IDataProviderMethod dataProviderMethod, ITestNGMethod method, ITestContext iTestContext) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName()
+ ".beforeDataProviderExecution_"
+ dataProviderMethod.getMethod().getName());
Expand All @@ -57,15 +55,15 @@ public void beforeDataProviderExecution(
@Override
public void afterDataProviderExecution(
IDataProviderMethod dataProviderMethod, ITestNGMethod method, ITestContext iTestContext) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName()
+ ".afterDataProviderExecution_"
+ dataProviderMethod.getMethod().getName());
}

@Override
public void onDataProviderFailure(ITestNGMethod method, ITestContext ctx, RuntimeException t) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName()
+ ".onDataProviderFailure_"
+ method.getDataProviderMethod().getMethod().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void flakyTest() {
}
}

@Test(timeOut = 2, priority = 4)
@Test(timeOut = 25, priority = 4)
public void timingOutTest() throws InterruptedException {
TimeUnit.MILLISECONDS.sleep(10);
TimeUnit.MILLISECONDS.sleep(100);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IExecutionListener;
import org.testng.ITestNGListener;
Expand All @@ -16,7 +15,6 @@ public class ExecutionListenerHolder {
"MasterShifu.onExecutionFinish",
"MasterOogway.onExecutionFinish"
};
public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = ExecutionListenerHolder.class.getName() + "$";

public static final List<ITestNGListener> ALL =
Expand All @@ -35,12 +33,12 @@ public class ExecutionListenerHolder {
public abstract static class KungFuWarrior implements IExecutionListener {
@Override
public void onExecutionStart() {
LOGS.add(getClass().getSimpleName() + ".onExecutionStart");
LogContainer.instance.log(getClass().getSimpleName() + ".onExecutionStart");
}

@Override
public void onExecutionFinish() {
LOGS.add(getClass().getSimpleName() + ".onExecutionFinish");
LogContainer.instance.log(getClass().getSimpleName() + ".onExecutionFinish");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.*;

public class ExecutionVisualiserHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = ExecutionVisualiserHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -34,7 +32,7 @@ public abstract static class KungFuWarrior implements IExecutionVisualiser {

@Override
public void consumeDotDefinition(String dotDefinition) {
LOGS.add(getClass().getSimpleName() + ".consumeDotDefinition");
LogContainer.instance.log(getClass().getSimpleName() + ".consumeDotDefinition");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
Expand All @@ -9,7 +8,6 @@

public class InvokedMethodListenerHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = InvokedMethodListenerHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand Down Expand Up @@ -107,15 +105,15 @@ public abstract static class KungFuWarrior implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
IInvokedMethodListener.super.beforeInvocation(method, testResult);
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName()
+ ".beforeInvocation_"
+ method.getTestMethod().getMethodName());
}

@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
LOGS.add(
LogContainer.instance.log(
getClass().getSimpleName()
+ ".afterInvocation_"
+ method.getTestMethod().getMethodName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.testng.internal.AutoCloseableLock;

public enum LogContainer {
instance;

private List<String> logs;

private final AutoCloseableLock lock = new AutoCloseableLock();

public void initialiseLogs() {
try (AutoCloseableLock ignore = lock.lock()) {
logs = new ArrayList<>();
}
}

public void log(String line) {
try (AutoCloseableLock ignore = lock.lock()) {
Objects.requireNonNull(logs).add(line);
}
}

public List<String> allLogs() {
if (logs == null || logs.isEmpty()) {
throw new IllegalStateException("Logs should have been initialised");
}
return Collections.synchronizedList(logs);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
Expand All @@ -9,7 +8,6 @@

public class MethodInterceptorHolder {

public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = MethodInterceptorHolder.class.getName() + "$";

public static final String[] EXPECTED_LOGS =
Expand All @@ -32,7 +30,7 @@ public abstract static class KungFuWarrior implements IMethodInterceptor {

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
LOGS.add(getClass().getSimpleName() + ".intercept");
LogContainer.instance.log(getClass().getSimpleName() + ".intercept");
return methods;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.listeners.issue2916;

import java.util.ArrayList;
import java.util.List;
import org.testng.ISuite;
import org.testng.ISuiteListener;
Expand All @@ -17,7 +16,6 @@ public class SuiteListenerHolder {
"MasterShifu.onFinish",
"MasterOogway.onFinish"
};
public static List<String> LOGS = new ArrayList<>();
private static final String PREFIX = SuiteListenerHolder.class.getName() + "$";

public static final List<ITestNGListener> ALL =
Expand All @@ -36,12 +34,12 @@ public abstract static class KungFuWarrior implements ISuiteListener {

@Override
public void onStart(ISuite suite) {
LOGS.add(getClass().getSimpleName() + ".onStart");
LogContainer.instance.log(getClass().getSimpleName() + ".onStart");
}

@Override
public void onFinish(ISuite suite) {
LOGS.add(getClass().getSimpleName() + ".onFinish");
LogContainer.instance.log(getClass().getSimpleName() + ".onFinish");
}
}

Expand Down
Loading

0 comments on commit 0b09262

Please sign in to comment.