diff --git a/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java b/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java index 50ffb5b5ec..1bf1ece439 100644 --- a/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java +++ b/modules/client-simulator/src/main/java/org/jpos/simulator/TestRunner.java @@ -22,6 +22,9 @@ import java.io.IOException; import java.io.FileInputStream; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.jpos.core.Environment; import org.jpos.iso.*; @@ -43,6 +46,8 @@ public class TestRunner MUX mux; ISOPackager packager; Interpreter bsh; + + long timeout; private static final String NL = System.getProperty("line.separator"); public static final long TIMEOUT = 60000; public TestRunner () { @@ -50,6 +55,7 @@ public TestRunner () { } protected void initService() throws ISOException { String packagerClass = cfg.get("packager", null); + timeout = cfg.getLong ("timeout", TIMEOUT); if (packagerClass != null) { try { packager = (ISOPackager) Class.forName(packagerClass).newInstance(); @@ -61,8 +67,23 @@ protected void initService() throws ISOException { } } protected void startService() { - for (int i=0; i { + try { + if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) { + log.warn("Runners didn't finish before global timeout"); + } + } catch (InterruptedException e) { + log.warn("interrupted while awaiting workers termination", e); + } + getServer().shutdown(); + }); + } } public void run () { try { @@ -78,8 +99,6 @@ public void run () { } catch (Throwable t) { getLog().error (t); } - if (cfg.getBoolean ("shutdown")) - getServer().shutdown(); } private void runSuite (List suite, MUX mux, Interpreter bsh) throws ISOException, IOException, EvalError @@ -147,7 +166,7 @@ private void runSuite (List suite, MUX mux, Interpreter bsh) ); ISOUtil.sleep (100); // let the channel do its logging first if (cfg.getBoolean ("shutdown")) - evt.addMessage ("Shutting down"); + evt.addMessage ("waiting for shutdown"); Logger.log (evt); } @@ -180,7 +199,7 @@ private List initSuite (Element suite) if (to != null) tc.setTimeout (Long.parseLong (to)); else - tc.setTimeout (cfg.getLong ("timeout", TIMEOUT)); + tc.setTimeout (timeout); l.add (tc); }