Skip to content
New issue

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

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

Already on GitHub? # to your account

Wait for all session workers to finish #275

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -43,13 +46,16 @@ 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 () {
super();
}
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();
Expand All @@ -61,8 +67,23 @@ protected void initService() throws ISOException {
}
}
protected void startService() {
for (int i=0; i<cfg.getInt("sessions", 1); i++)
new Thread(this).start();
int sessions = cfg.getInt("sessions", 1);
ExecutorService executor = Executors.newCachedThreadPool();
for (int i=0; i<sessions; i++)
executor.execute(this);
executor.shutdown();
if (cfg.getBoolean ("shutdown")) {
Executors.newSingleThreadExecutor().execute( () -> {
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 {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -180,7 +199,7 @@ private List<TestCase> initSuite (Element suite)
if (to != null)
tc.setTimeout (Long.parseLong (to));
else
tc.setTimeout (cfg.getLong ("timeout", TIMEOUT));
tc.setTimeout (timeout);
l.add (tc);

}
Expand Down