Skip to content

Commit ff9bff2

Browse files
committed
Handle process better in Host
The method to check if a command exists asks for the help of this command now (instead of checking if the command name is in the output of rabbitmqctl). This way we just have to check the exit code (0 if the command exists). We also use a timeout to wait for the end of the process. A test hangs on the CI environment, these changes try to fix this. (cherry picked from commit 6b2251f)
1 parent 7beb472 commit ff9bff2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/test/java/com/rabbitmq/tools/Host.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Java client library, is triple-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -28,12 +28,17 @@
2828
import com.rabbitmq.client.ConnectionFactory;
2929
import com.rabbitmq.client.impl.NetworkConnection;
3030
import com.rabbitmq.client.test.TestUtils;
31+
import java.util.concurrent.TimeUnit;
3132
import java.util.function.Predicate;
3233
import java.util.regex.Matcher;
3334
import java.util.regex.Pattern;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3437

3538
public class Host {
3639

40+
private static final Logger LOGGER = LoggerFactory.getLogger(Host.class);
41+
3742
private static final String DOCKER_PREFIX = "DOCKER:";
3843
private static final Pattern CONNECTION_NAME_PATTERN = Pattern.compile("\"connection_name\",\"(?<name>[a-zA-Z0-9\\-]+)?\"");
3944

@@ -78,7 +83,14 @@ private static int waitForExitValue(Process pr) {
7883
public static Process executeCommandIgnoringErrors(String command) throws IOException
7984
{
8085
Process pr = executeCommandProcess(command);
81-
waitForExitValue(pr);
86+
boolean exited = false;
87+
try {
88+
exited = pr.waitFor(30, TimeUnit.SECONDS);
89+
} catch (InterruptedException e) {
90+
}
91+
if (!exited) {
92+
LOGGER.warn("Command '{}' did not finish in 30 seconds", command);
93+
}
8294
return pr;
8395
}
8496

@@ -101,9 +113,9 @@ private static Process executeCommandProcess(String command) throws IOException
101113
}
102114

103115
public static boolean isRabbitMqCtlCommandAvailable(String command) throws IOException {
104-
Process process = rabbitmqctlIgnoreErrors("");
105-
String stderr = capture(process.getErrorStream());
106-
return stderr.contains(command);
116+
Process process = rabbitmqctlIgnoreErrors(command + " --help");
117+
int exitValue = process.exitValue();
118+
return exitValue == 0;
107119
}
108120

109121
public static Process rabbitmqctl(String command) throws IOException {

0 commit comments

Comments
 (0)