Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] Timeout test #1878

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions src/test/java/org/apache/sysds/test/AutomatedTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -1435,31 +1439,49 @@ protected ByteArrayOutputStream runTest(Class<?> expectedException, String errMe
*/
protected ByteArrayOutputStream runTest(boolean newWay, boolean exceptionExpected, Class<?> expectedException,
String errMessage, int maxSparkInst) {

ExecutorService executor = Executors.newSingleThreadExecutor();
try{
return executor.submit(() ->
runTestWithTimeout(newWay,exceptionExpected,expectedException,errMessage, maxSparkInst))//
.get(1000, TimeUnit.SECONDS);
}
catch(TimeoutException e){
throw new RuntimeException("Our tests should run faster than 1000 sec each",e);
}
catch(Exception e){
throw new RuntimeException(e);
}
finally{
executor.shutdown();
}
}

private ByteArrayOutputStream runTestWithTimeout(boolean newWay, boolean exceptionExpected, Class<?> expectedException,
String errMessage, int maxSparkInst){
String name = "";
final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
for(int i = 0; i < ste.length; i++) {
if(ste[i].getMethodName().equalsIgnoreCase("invoke0"))
name = ste[i - 1].getClassName() + "." + ste[i - 1].getMethodName();
}
LOG.info("Test method name: " + name);

String executionFile = sourceDirectory + selectedTest + ".dml";

if(!newWay) {
executionFile = executionFile + "t";
ParameterBuilder.setVariablesInScript(sourceDirectory, selectedTest + ".dml", testVariables);
}

// cleanup scratch folder (prevent side effect between tests)
cleanupScratchSpace();

ArrayList<String> args = new ArrayList<>();
// setup arguments to SystemDS
if(DEBUG) {
args.add("-Dsystemds.logging=trace");
}

if(newWay) {
// Need a null pointer check because some tests read DML from a string.
if(null != fullDMLScriptName) {
Expand All @@ -1471,38 +1493,38 @@ protected ByteArrayOutputStream runTest(boolean newWay, boolean exceptionExpecte
args.add("-f");
args.add(executionFile);
}

addProgramIndependentArguments(args, programArgs);

// program-specific parameters
if(newWay) {
for(int i = 0; i < programArgs.length; i++)
args.add(programArgs[i]);
}

if(DEBUG) {
if(!newWay)
TestUtils.printDMLScript(executionFile);
else {
TestUtils.printDMLScript(fullDMLScriptName);
}
}

ByteArrayOutputStream buff = outputBuffering ? new ByteArrayOutputStream() : null;
PrintStream old = System.out;
if(outputBuffering)
System.setOut(new PrintStream(buff));

try {
String[] dmlScriptArgs = args.toArray(new String[args.size()]);
if(LOG.isTraceEnabled())
LOG.trace("arguments to DMLScript: " + Arrays.toString(dmlScriptArgs));
main(dmlScriptArgs);

if(maxSparkInst > -1 && maxSparkInst < Statistics.getNoOfCompiledSPInst())
fail("Limit of Spark jobs is exceeded: expected: " + maxSparkInst + ", occurred: "
+ Statistics.getNoOfCompiledSPInst());

if(exceptionExpected)
fail("expected exception which has not been raised: " + expectedException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected String waitForCoordinators() {
}

protected String waitForCoordinators(int timeout){
ExecutorService executor = Executors.newCachedThreadPool();
ExecutorService executor = Executors.newSingleThreadExecutor();
try{
return executor.submit(() -> waitForCoordinatorsActual()).get(timeout, TimeUnit.SECONDS);
}
Expand Down