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

[JBWS-4407]:Fix test execution on windows is 10x slower than on linux #364

Merged
merged 1 commit into from
Dec 24, 2023
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 @@ -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,29 @@ 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 {
boolean exited = p.waitFor(PROCESS_TIMEOUT, TimeUnit.SECONDS);
assertTrue("Process isn't exited in " + PROCESS_TIMEOUT + " seconds", exited);
String fallbackMessage = "Process did exit with status " + p.exitValue();
jimma marked this conversation as resolved.
Show resolved Hide resolved
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