Skip to content

Commit

Permalink
Add tests for test parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
Thevakumar-Luheerathan committed May 11, 2023
1 parent a751e26 commit 1d6bcd4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,58 @@ function executeTests() returns error? {

}

int paralalTestExecutionListLength = parallelTestExecutionList.length();
int serialTestExecutionListLength = serialTestExecutionList.length();

while true {
if (parallelTestExecutionList.length() == 0 && getAvailableWorkerCount() == testWorkers
&& serialTestExecutionList.length() == 0) {

TestFunction? testFunction = ();
lock {
paralalTestExecutionListLength = parallelTestExecutionList.length();
serialTestExecutionListLength = serialTestExecutionList.length();
}
//Exit from the loop if there are no tests to execute and all jobs are released
if (paralalTestExecutionListLength == 0 && getAvailableWorkerCount() == testWorkers
&& serialTestExecutionListLength == 0) {
break;
}

if (getAvailableWorkerCount() != 0) {

if parallelTestExecutionList.length() == 0 && serialTestExecutionList.length() == 0 {
if paralalTestExecutionListLength == 0 && serialTestExecutionListLength == 0 {
runtime:sleep(0.0001);
continue;

}

if (serialTestExecutionList.length() != 0 && getAvailableWorkerCount() == testWorkers) {
if (serialTestExecutionListLength != 0 && getAvailableWorkerCount() == testWorkers) {
lock {
testFunction = serialTestExecutionList.remove(0);
}

TestFunction testFunction = serialTestExecutionList.remove(0);
allocateWorker();
future<error?> serialWaiter = start executeTest(testFunction);
any _ = check wait serialWaiter;
if testFunction is TestFunction {
allocateWorker();
future<error?> serialWaiter = start executeTest(testFunction);
any _ = check wait serialWaiter;
}

} else if parallelTestExecutionList.length() != 0 && serialTestExecutionList.length() == 0 {
TestFunction testFunction = parallelTestExecutionList.remove(0);
allocateWorker();
future<(error?)> parallelWaiter = start executeTest(testFunction);
runtime:sleep(0.0001);
if isDataDrivenTest(testFunction) {
any _ = check wait parallelWaiter;
} else if paralalTestExecutionListLength != 0 && serialTestExecutionListLength == 0 {
lock {
testFunction = parallelTestExecutionList.remove(0);
}
if testFunction is TestFunction {
allocateWorker();
future<(error?)> parallelWaiter = start executeTest(testFunction);
if isDataDrivenTest(testFunction) {
any _ = check wait parallelWaiter;
}
}

}
} else {
runtime:sleep(0.0001);
}
runtime:sleep(0.0001);
}
// println("Test execution time :" + (currentTimeInMillis() - startTime).toString() + "ms");
println("\n\t\tTest execution time :" + (currentTimeInMillis() - startTime).toString() + "ms\n");
}

function executeTest(TestFunction testFunction) returns error? {
Expand Down Expand Up @@ -161,7 +177,6 @@ function executeTest(TestFunction testFunction) returns error? {
}
testFunction.dependents.forEach(dependent => checkExecutionReadiness(dependent));
releaseWorker();
// isSerialTestExecution = !isSerialTestExecution && !testFunction.parallelizable;
}

function checkExecutionReadiness(TestFunction testFunction) {
Expand Down Expand Up @@ -227,8 +242,19 @@ function executeDataDrivenTestSet(TestFunction testFunction) returns error? {
runtime:sleep(0.0001);
continue;
}
runtime:sleep(0.0001);
}

while true {
if getAvailableWorkerCount() > 0 {
break;
}
runtime:sleep(0.0001);
}

if !isIntialJob {
allocateWorker();
}
allocateWorker();
}

function prepareDataDrivenTest(TestFunction testFunction, string key, AnyOrError[] value, TestType testType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class CommonUtils {
private CommonUtils() {
}

public static String replaceExecutionTime(String content) {
return replaceVaryingString("Test execution time :", "ms", content);
}

public static String replaceVaryingString(String firstString, String endString, String content) {
String modifiedContent = content;
int firstPos = modifiedContent.indexOf(firstString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ under the License.
<class name="org.ballerinalang.testerina.test.ExcludeFromCodeCoverageTest"/>
<class name="org.ballerinalang.testerina.test.ConfigurableCliArgsTest"/>
<class name="org.ballerinalang.testerina.test.negative.InvalidConfigurableCliArgsTestCase"/>
<class name="org.ballerinalang.testerina.test.TestparallelizationTest"/>
</classes>
</test>
</suite>

0 comments on commit 1d6bcd4

Please sign in to comment.