Skip to content
Open
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 @@ -25,7 +25,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -173,6 +175,16 @@ static VaadinDevCli of(Path app) {
* @return the exit code and the whole output
*/
Outcome run(String... arguments) {
String verb = "vaadin-dev " + String.join(" ", arguments);
boolean start = arguments.length > 0 && arguments[0].equals("start");
HungStarts hung = start ? HUNG_STARTS.get(app) : null;
if (hung != null && hung.count() >= MAX_HUNG_STARTS) {
throw new AssertionError(verb + " was not tried: the last "
+ hung.count() + " starts of " + app + " did not finish in "
+ COMMAND_TIMEOUT.toMinutes()
+ " minutes in this test run. The last one said:\n"
+ hung.output());
}
List<String> command = launcher.command(app, List.of(arguments))
.orElseThrow(() -> new IllegalStateException(
launcher + " cannot run here"));
Expand All @@ -196,7 +208,6 @@ Outcome run(String... arguments) {
+ " -Dvaadin.dev.compiler=" + compiler());
// No spinner: the output is read by assertions, not by a person.
builder.environment().put("VAADIN_DEV_PROGRESS", "never");
String verb = "vaadin-dev " + String.join(" ", arguments);
try {
Process process = builder.start();
// Read on a thread of its own so the timeout below actually holds:
Expand Down Expand Up @@ -227,6 +238,12 @@ Outcome run(String... arguments) {
.forEach(ProcessHandle::destroyForcibly);
process.destroyForcibly();
reader.join(OUTPUT_DRAIN_TIMEOUT.toMillis());
if (start) {
String said = textOf(output);
HUNG_STARTS.merge(app, new HungStarts(1, said),
(before, now) -> new HungStarts(
before.count() + 1, said));
}
throw new AssertionError(verb + " did not finish in "
+ COMMAND_TIMEOUT.toMinutes()
+ " minutes; it said:\n" + textOf(output));
Expand All @@ -238,6 +255,9 @@ Outcome run(String... arguments) {
+ " but something it started still holds its"
+ " output open; it said:\n" + textOf(output));
}
if (start) {
HUNG_STARTS.remove(app);
}
return new Outcome(process.exitValue(), textOf(output));
} finally {
in.close();
Expand Down Expand Up @@ -322,6 +342,39 @@ private void shutdownWhenThisJvmExits() {
*/
private static final Duration OUTPUT_DRAIN_TIMEOUT = Duration.ofSeconds(30);

/**
* How many {@code start} commands in a row may run into
* {@link #COMMAND_TIMEOUT} before the next one is not tried at all.
* <p>
* Every test begins with a start, so without a limit one server that cannot
* boot costs five minutes per test and uses up the CI step's timeout before
* the other fixtures run. One timeout is still retried: a first start can
* be slow once, for example while a server is downloaded and unpacked.
*/
private static final int MAX_HUNG_STARTS = 2;

/**
* The {@code start} commands in a row that did not finish in
* {@link #COMMAND_TIMEOUT}, per application, and what the last one said. A
* start that finishes in time removes the entry. The tests still fail, with
* that output, so nothing is hidden. The map lives as long as the test JVM,
* which is one failsafe execution of one fixture, so the next execution
* tries again. Only a timeout counts: a start that exits with an error is
* already fast.
*/
private static final Map<Path, HungStarts> HUNG_STARTS = new ConcurrentHashMap<>();

/**
* Starts of one application that did not finish in time.
*
* @param count
* how many in a row
* @param output
* what the last one said
*/
private record HungStarts(int count, String output) {
}

/** The daemon's handshake, and the only way the CLI can find it. */
private static final String HANDSHAKE = ".vaadin/daemon.properties";

Expand Down
Loading