Exit gradle run task if any node dies (#60789)
The Elasticsearch `run` task in Gradle is backed by testclusters spinning up a node and waiting indefinitely on output from that node. However, this thread currently waits for an interrupt to exit. If Elasticsearch fails to start, we hang indefinitely. This commit adds a check after each poll of the process stdout to see if it is still alive, and fails the build if it has died. closes #60761
This commit is contained in:
parent
ddcfbec569
commit
cf39a69be3
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.gradle.testclusters;
|
||||
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.gradle.api.logging.Logging;
|
||||
import org.gradle.api.tasks.Input;
|
||||
|
@ -34,6 +35,7 @@ import java.nio.file.Paths;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -131,11 +133,13 @@ public class RunTask extends DefaultTestClustersTask {
|
|||
@TaskAction
|
||||
public void runAndWait() throws IOException {
|
||||
List<BufferedReader> toRead = new ArrayList<>();
|
||||
List<BooleanSupplier> aliveChecks = new ArrayList<>();
|
||||
try {
|
||||
for (ElasticsearchCluster cluster : getClusters()) {
|
||||
for (ElasticsearchNode node : cluster.getNodes()) {
|
||||
BufferedReader reader = Files.newBufferedReader(node.getEsStdoutFile());
|
||||
toRead.add(reader);
|
||||
aliveChecks.add(node::isProcessAlive);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,6 +152,10 @@ public class RunTask extends DefaultTestClustersTask {
|
|||
}
|
||||
}
|
||||
|
||||
if (aliveChecks.stream().allMatch(BooleanSupplier::getAsBoolean) == false) {
|
||||
throw new GradleException("Elasticsearch cluster died");
|
||||
}
|
||||
|
||||
if (readData == false) {
|
||||
// no data was ready to be consumed and rather than continuously spinning, pause
|
||||
// for some time to avoid excessive CPU usage. Ideally we would use the JDK
|
||||
|
|
Loading…
Reference in New Issue