Skip to content

[9.0] [Test] Rework detecting elasticsearch process in docker tests (#128013) #128101

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

Merged
merged 1 commit into from
May 16, 2025
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
@@ -75,6 +75,13 @@ public class Docker {
public static final int STARTUP_SLEEP_INTERVAL_MILLISECONDS = 1000;
public static final int STARTUP_ATTEMPTS_MAX = 30;

private static final String ELASTICSEARCH_FULL_CLASSNAME = "org.elasticsearch.bootstrap.Elasticsearch";
private static final String FIND_ELASTICSEARCH_PROCESS = "for pid in $(ps -eo pid,comm | grep java | awk '\\''{print $1}'\\''); "
+ "do cmdline=$(tr \"\\0\" \" \" < /proc/$pid/cmdline 2>/dev/null); [[ $cmdline == *"
+ ELASTICSEARCH_FULL_CLASSNAME
+ "* ]] && echo \"$pid: $cmdline\"; done";
// The length of the command exceeds what we can use for COLUMNS so we use a pipe to detect the process we're looking for

/**
* Tracks the currently running Docker image. An earlier implementation used a fixed container name,
* but that appeared to cause problems with repeatedly destroying and recreating containers with
@@ -185,11 +192,8 @@ public static void waitForElasticsearchToStart() {
try {
// Give the container enough time for security auto-configuration or a chance to crash out
Thread.sleep(STARTUP_SLEEP_INTERVAL_MILLISECONDS);

// Set COLUMNS so that `ps` doesn't truncate its output
psOutput = dockerShell.run("bash -c 'COLUMNS=4000 ps ax'").stdout();

if (psOutput.contains("org.elasticsearch.bootstrap.Elasticsearch")) {
psOutput = dockerShell.run("bash -c '" + FIND_ELASTICSEARCH_PROCESS + " | wc -l'").stdout();
if (psOutput.contains("1")) {
isElasticsearchRunning = true;
break;
}