Skip to content

Commit

Permalink
[JBWS-4407]:Fix test execution on windows is 10x slower than on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
jimma committed Dec 20, 2023
1 parent 18ea784 commit 97bb927
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.StringTokenizer;

import java.util.concurrent.TimeUnit;
import javax.management.MBeanServerConnection;
import javax.naming.InitialContext;
import javax.naming.NamingException;
Expand Down Expand Up @@ -63,11 +64,10 @@
public abstract class JBossWSTest extends Assert
{
protected static Logger log = Logger.getLogger(JBossWSTest.class.getName());
public static final String SYSPROP_COPY_JOB_TIMEOUT = "test.copy.job.timeout";
public static final String SYSPROP_PROCESS_TIMEOUT = "test.process.wait.timeout";
public static final String CXF_TESTS_GROUP_QUALIFIER = "cxf-tests";
public static final String SHARED_TESTS_GROUP_QUALIFIER = "shared-tests";
private static final int COPY_JOB_TIMEOUT = Integer.getInteger(SYSPROP_COPY_JOB_TIMEOUT, File.pathSeparatorChar == ':' ? 5000 : 60000); //60s on Windows, 5s on UNIX and Mac

private static final int PROCESS_TIMEOUT = Integer.getInteger(SYSPROP_PROCESS_TIMEOUT, File.pathSeparatorChar == ':' ? 10 : 30); //30s on Windows, 10s on UNIX and Mac
public JBossWSTest()
{
}
Expand Down Expand Up @@ -162,35 +162,28 @@ public static void executeCommand(String command, OutputStream os, String messag
private static void executeCommand(List<String> command, OutputStream os, String message, Map<String, String> env) throws IOException
{
ProcessBuilder pb = new ProcessBuilder(command);
if (env != null)
{
for (String variable : env.keySet())
{
if (System.getProperty("os.name").toLowerCase().contains("win")) {
pb.environment().put("NOPAUSE", "true");
}
if (env != null) {
for (String variable : env.keySet()) {
pb.environment().put(variable, env.get(variable));
}
}
Process p = pb.start();
CopyJob inputStreamJob = new CopyJob(p.getInputStream(), os == null ? System.out : os);
CopyJob errorStreamJob = new CopyJob(p.getErrorStream(), System.err);
// unfortunately the following threads are needed because of Windows behavior
Thread inputJob = new Thread(inputStreamJob);
Thread outputJob = new Thread(errorStreamJob);
try
{
inputJob.start();
inputJob.join(COPY_JOB_TIMEOUT);
outputJob.start();
outputJob.join(COPY_JOB_TIMEOUT);
int statusCode = p.waitFor();
String fallbackMessage = "Process did exit with status " + statusCode;
assertTrue(message != null ? message : fallbackMessage, statusCode == 0);
}
catch (InterruptedException ie)
{
inputJob.start();
outputJob.start();
try {
p.waitFor(PROCESS_TIMEOUT, TimeUnit.SECONDS);
String fallbackMessage = "Process did exit with status " + p.exitValue();
assertTrue(message != null ? message : fallbackMessage, p.exitValue() == 0);
} catch (InterruptedException ie) {
ie.printStackTrace(System.err);
}
finally
{
} finally {
inputStreamJob.kill();
errorStreamJob.kill();
p.destroy();
Expand Down

0 comments on commit 97bb927

Please sign in to comment.