Skip to content

Commit

Permalink
Merge pull request #40279 from Thevakumar-Luheerathan/testerina-test-…
Browse files Browse the repository at this point in the history
…parallelization

Add concurrent test support
  • Loading branch information
Thevakumar-Luheerathan authored Feb 28, 2024
2 parents bb0abfc + 37f2a74 commit 13c0e50
Show file tree
Hide file tree
Showing 305 changed files with 5,883 additions and 976 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class TestArguments {

private static final int ARGUMENTS_NUMBER = 10;
private static final int ARGUMENTS_NUMBER = 11;

private final Class<?>[] argTypes;
private final Object[] argValues;
Expand All @@ -49,6 +49,7 @@ public TestArguments(String... args) {
assignValues(7, args[7]);
assignValues(8, args[8]);
assignValues(9, args[9]);
assignValues(10, args[10]);
}

public Object[] getArgValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public TestCommand() {
@CommandLine.Option(names = "--debug", description = "start in remote debugging mode")
private String debugPort;

@CommandLine.Option(names = "--parallel", description = "enable parallel execution", defaultValue = "false")
private boolean isParallelExecution;

@CommandLine.Option(names = "--list-groups", description = "list the groups available in the tests")
private boolean listGroups;

Expand Down Expand Up @@ -343,10 +346,10 @@ public void execute() {
.addTask(new CompileTask(outStream, errStream, false, isPackageModified, buildOptions.enableCache()))
// .addTask(new CopyResourcesTask(), listGroups) // merged with CreateJarTask
.addTask(new RunTestsTask(outStream, errStream, rerunTests, groupList, disableGroupList, testList,
includes, coverageFormat, moduleMap, listGroups, excludes, cliArgs),
includes, coverageFormat, moduleMap, listGroups, excludes, cliArgs, isParallelExecution),
project.buildOptions().nativeImage())
.addTask(new RunNativeImageTestTask(outStream, rerunTests, groupList, disableGroupList,
testList, includes, coverageFormat, moduleMap, listGroups),
testList, includes, coverageFormat, moduleMap, listGroups, isParallelExecution),
!project.buildOptions().nativeImage())
.addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,13 @@ public void run() {
private boolean isRerunTestExecution;
private String singleExecTests;
private boolean listGroups;
private final boolean isParallelExecution;

TestReport testReport;

public RunNativeImageTestTask(PrintStream out, boolean rerunTests, String groupList,
String disableGroupList, String testList, String includes, String coverageFormat,
Map<String, Module> modules, boolean listGroups) {
Map<String, Module> modules, boolean listGroups, boolean isParallelExecution) {
this.out = out;
this.isRerunTestExecution = rerunTests;

Expand All @@ -154,6 +155,7 @@ public RunNativeImageTestTask(PrintStream out, boolean rerunTests, String groupL
singleExecTests = testList;
}
this.listGroups = listGroups;
this.isParallelExecution = isParallelExecution;
}


Expand Down Expand Up @@ -556,6 +558,7 @@ private int runTestSuiteWithNativeImage(Package currentPackage, Target target,
cmdArgs.add(this.singleExecTests != null ? this.singleExecTests : "");
cmdArgs.add(Boolean.toString(isRerunTestExecution));
cmdArgs.add(Boolean.toString(listGroups)); // 8
cmdArgs.add(Boolean.toString(isParallelExecution));

builder.command(cmdArgs.toArray(new String[0]));
process = builder.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class RunTestsTask implements Task {
private boolean listGroups;
private final List<String> cliArgs;

private final boolean isParallelExecution;

TestReport testReport;
private static final Boolean isWindows = System.getProperty("os.name").toLowerCase(Locale.getDefault())
.contains("win");
Expand All @@ -122,11 +124,13 @@ public class RunTestsTask implements Task {

public RunTestsTask(PrintStream out, PrintStream err, boolean rerunTests, String groupList,
String disableGroupList, String testList, String includes, String coverageFormat,
Map<String, Module> modules, boolean listGroups, String excludes, String[] cliArgs) {
Map<String, Module> modules, boolean listGroups, String excludes, String[] cliArgs,
boolean isParallelExecution) {
this.out = out;
this.err = err;
this.isRerunTestExecution = rerunTests;
this.cliArgs = List.of(cliArgs);
this.isParallelExecution = isParallelExecution;

if (disableGroupList != null) {
this.disableGroupList = disableGroupList;
Expand Down Expand Up @@ -349,6 +353,7 @@ private int runTestSuite(Target target, Package currentPackage, JBallerinaBacken
cmdArgs.add(this.singleExecTests != null ? this.singleExecTests : "");
cmdArgs.add(Boolean.toString(isRerunTestExecution));
cmdArgs.add(Boolean.toString(listGroups));
cmdArgs.add(Boolean.toString(isParallelExecution));
cliArgs.forEach((arg) -> {
cmdArgs.add(arg);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ public class NativeUtils {

private static final ReflectConfigClassMethod REFLECTION_CONFIG_EXECUTE_METHOD = new ReflectConfigClassMethod(
TEST_EXEC_FUNCTION, new String[]{"io.ballerina.runtime.internal.scheduling.Strand",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString"
});
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString",
"io.ballerina.runtime.api.values.BString"
});

//Add dynamically loading classes and methods to reflection config
public static void createReflectConfig(Path nativeConfigPath, Package currentPackage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ OPTIONS
--graalvm-build-options
Additional build options to be passed to the GraalVM native image.

--parallel
Enable parallel execution of tests.

ARGUMENTS
(-Ckey=value)...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ name = "jballerina.java"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
Expand All @@ -22,13 +42,20 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ public class TestFunctionVisitor extends NodeVisitor {

static final List<String> TEST_STATIC_ANNOTATION_NAMES = List.of(
"Config", "BeforeSuite", "AfterSuite", "BeforeGroups", "AfterGroups", "BeforeEach", "AfterEach");
static final String CONFIG_ANNOTATION = "Config";
private static final String TEST_DYNAMIC_ANNOTATION_NAME = "Factory";
private static final String TEST_MODULE_NAME = "test";

private final List<FunctionDefinitionNode> testStaticFunctions;
private final List<FunctionDefinitionNode> testSetUpTearDownFunctions;
private final List<FunctionDefinitionNode> testDynamicFunctions;
private final List<FunctionDefinitionNode> testFunctions;

public TestFunctionVisitor() {
this.testStaticFunctions = new ArrayList<>();
this.testSetUpTearDownFunctions = new ArrayList<>();
this.testDynamicFunctions = new ArrayList<>();
this.testFunctions = new ArrayList<>();
}

@Override
Expand All @@ -73,7 +76,11 @@ public void visit(FunctionDefinitionNode functionDefinitionNode) {
String identifier = qualifiedNameReferenceNode.identifier().text();
if (TEST_MODULE_NAME.equals(modulePrefix)) {
if (TEST_STATIC_ANNOTATION_NAMES.contains(identifier)) {
testStaticFunctions.add(functionDefinitionNode);
if (CONFIG_ANNOTATION.equals(identifier)) {
testFunctions.add(functionDefinitionNode);
} else {
testSetUpTearDownFunctions.add(functionDefinitionNode);
}
} else if (TEST_DYNAMIC_ANNOTATION_NAME.equals(identifier)) {
testDynamicFunctions.add(functionDefinitionNode);
}
Expand All @@ -83,7 +90,9 @@ public void visit(FunctionDefinitionNode functionDefinitionNode) {
}

public List<FunctionDefinitionNode> getTestStaticFunctions() {
return this.testStaticFunctions;
List<FunctionDefinitionNode> testStaticFunctions = new ArrayList<>(testSetUpTearDownFunctions);
testStaticFunctions.addAll(testFunctions);
return testStaticFunctions;
}

public List<FunctionDefinitionNode> getTestDynamicFunctions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TesterinaCompilerPluginConstants {
public static final String TESTS_PARAMETER = "tests";
public static final String RERUN_FAILED_PARAMETER = "rerunFailed";
public static final String LIST_GROUPS_PARAMETER = "listGroups";
public static final String PARALLEL_EXECUTION_PARAMETER = "parallelExecution";

private TesterinaCompilerPluginConstants() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public static void addSetTestOptionsCall(List<StatementNode> statements) {
getPositionalArg(TesterinaCompilerPluginConstants.DISABLE_GROUPS_PARAMETER),
getPositionalArg(TesterinaCompilerPluginConstants.TESTS_PARAMETER),
getPositionalArg(TesterinaCompilerPluginConstants.RERUN_FAILED_PARAMETER),
getPositionalArg(TesterinaCompilerPluginConstants.LIST_GROUPS_PARAMETER)))));
getPositionalArg(TesterinaCompilerPluginConstants.LIST_GROUPS_PARAMETER),
getPositionalArg(TesterinaCompilerPluginConstants.PARALLEL_EXECUTION_PARAMETER)))));
}

public static void addStartSuiteCall(List<StatementNode> statements) {
Expand Down Expand Up @@ -284,7 +285,9 @@ public static FunctionSignatureNode getFunctionSignature() {
NodeFactory.createToken(SyntaxKind.COMMA_TOKEN),
getStringParameter(TesterinaCompilerPluginConstants.RERUN_FAILED_PARAMETER),
NodeFactory.createToken(SyntaxKind.COMMA_TOKEN),
getStringParameter(TesterinaCompilerPluginConstants.LIST_GROUPS_PARAMETER)),
getStringParameter(TesterinaCompilerPluginConstants.LIST_GROUPS_PARAMETER),
NodeFactory.createToken(SyntaxKind.COMMA_TOKEN),
getStringParameter(TesterinaCompilerPluginConstants.PARALLEL_EXECUTION_PARAMETER)),
NodeFactory.createToken(SyntaxKind.CLOSE_PAREN_TOKEN), returnTypeDescriptorNode);
}

Expand Down
Loading

0 comments on commit 13c0e50

Please sign in to comment.