This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new d28921a0bd [MINOR] Timeout test (#1878)
d28921a0bd is described below

commit d28921a0bdecaa1af411e1b2efa13e94dc47b9ec
Author: Sebastian Baunsgaard <[email protected]>
AuthorDate: Wed Aug 9 13:05:18 2023 +0200

    [MINOR] Timeout test (#1878)
    
    This commit adds a timeout on all tests of 1000 seconds.
    this means in practice that the github actions does not stall for 1.5
    hours, if something is wrong.
---
 .../org/apache/sysds/test/AutomatedTestBase.java   | 48 ++++++++++++++++------
 .../federated/multitenant/MultiTenantTestBase.java |  2 +-
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java 
b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
index 08d7478f07..aee80e5f1c 100644
--- a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
+++ b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
@@ -38,6 +38,10 @@ import java.util.List;
 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;
@@ -1435,7 +1439,25 @@ public abstract class AutomatedTestBase {
         */
        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++) {
@@ -1443,23 +1465,23 @@ public abstract class AutomatedTestBase {
                                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) {
@@ -1471,15 +1493,15 @@ public abstract class AutomatedTestBase {
                        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);
@@ -1487,22 +1509,22 @@ public abstract class AutomatedTestBase {
                                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);
                }
diff --git 
a/src/test/java/org/apache/sysds/test/functions/federated/multitenant/MultiTenantTestBase.java
 
b/src/test/java/org/apache/sysds/test/functions/federated/multitenant/MultiTenantTestBase.java
index 0b4e193ac4..685acf1ab9 100644
--- 
a/src/test/java/org/apache/sysds/test/functions/federated/multitenant/MultiTenantTestBase.java
+++ 
b/src/test/java/org/apache/sysds/test/functions/federated/multitenant/MultiTenantTestBase.java
@@ -138,7 +138,7 @@ public abstract class MultiTenantTestBase extends 
AutomatedTestBase {
        }
 
        protected String waitForCoordinators(int timeout){
-               ExecutorService executor = Executors.newCachedThreadPool();
+               ExecutorService executor = Executors.newSingleThreadExecutor();
                try{
                        return executor.submit(() -> 
waitForCoordinatorsActual()).get(timeout, TimeUnit.SECONDS);
                }

Reply via email to