Skip to content

Commit 4f37a2e

Browse files
authored
Update serverboot test to be more resilient (#5609)
* GH-0000 Update SIGINT shutdown fallback * GH-0000 Format ServerBootSignalIT indentation * GH-0000 Apply formatter to ServerBootSignalIT
1 parent 1fd83f7 commit 4f37a2e

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

tools/server-boot/src/test/java/org/eclipse/rdf4j/tools/serverboot/ServerBootSignalIT.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@
5151
import org.junit.jupiter.api.Test;
5252
import org.junit.jupiter.api.condition.EnabledOnOs;
5353
import org.junit.jupiter.api.condition.OS;
54+
import org.slf4j.Logger;
55+
import org.slf4j.LoggerFactory;
5456

5557
@EnabledOnOs({ OS.LINUX, OS.MAC })
5658
class ServerBootSignalIT {
5759

60+
private static final Logger LOGGER = LoggerFactory.getLogger(ServerBootSignalIT.class);
61+
5862
private ExecutorService streamExecutor;
5963
private final List<Runnable> cleanupActions = new ArrayList<>();
6064

@@ -82,15 +86,23 @@ void tearDown() {
8286

8387
@Test
8488
void gracefullyStopsOnSigint() throws Exception {
85-
assertGracefulShutdown("INT");
89+
assertGracefulShutdownWithSigintFallback();
8690
}
8791

8892
@Test
8993
void gracefullyStopsOnSigterm() throws Exception {
9094
assertGracefulShutdown("TERM");
9195
}
9296

97+
private void assertGracefulShutdownWithSigintFallback() throws Exception {
98+
assertGracefulShutdown("INT", true);
99+
}
100+
93101
private void assertGracefulShutdown(String signalName) throws Exception {
102+
assertGracefulShutdown(signalName, false);
103+
}
104+
105+
private void assertGracefulShutdown(String signalName, boolean allowSigtermFallback) throws Exception {
94106
Path projectRoot = Path.of("").toAbsolutePath();
95107
String javaBin = Path.of(System.getProperty("java.home"), "bin", "java").toString();
96108
int serverPort = findFreePort();
@@ -121,7 +133,7 @@ private void assertGracefulShutdown(String signalName) throws Exception {
121133

122134
boolean startedInTime = started.await(90, SECONDS);
123135
assertThat(startedInTime)
124-
.as(() -> "Server failed to start within timeout. Output:\n" + outputBuffer)
136+
.as(() -> "Server failed to start within timeout. Output:\\n" + outputBuffer)
125137
.isTrue();
126138

127139
String serverUrl = serverUrl(serverPort);
@@ -130,12 +142,20 @@ private void assertGracefulShutdown(String signalName) throws Exception {
130142
long pid = process.pid();
131143
sendSignal(pid, signalName);
132144

133-
boolean exited = process.waitFor(30, SECONDS);
145+
boolean exited = process.waitFor(allowSigtermFallback ? 5 : 30, SECONDS);
146+
if (!exited && allowSigtermFallback) {
147+
LOGGER.warn("Server did not exit on SIGINT within 5 seconds. Sending SIGTERM.");
148+
sendSignal(pid, "TERM");
149+
exited = process.waitFor(5, SECONDS);
150+
assertThat(exited)
151+
.as(() -> "Process did not exit after SIGTERM. Output:\\n" + outputBuffer)
152+
.isTrue();
153+
}
134154
assertThat(exited)
135-
.as(() -> "Process did not exit after SIG" + signalName + ". Output:\n" + outputBuffer)
155+
.as(() -> "Process did not exit after SIG" + signalName + ". Output:\\n" + outputBuffer)
136156
.isTrue();
137157
assertThat(process.exitValue())
138-
.as(() -> "Process exit value after SIG" + signalName + ". Output:\n" + outputBuffer)
158+
.as(() -> "Process exit value after SIG" + signalName + ". Output:\\n" + outputBuffer)
139159
.isEqualTo(0);
140160
}
141161

@@ -239,7 +259,7 @@ private RemoteRepositoryManager awaitRepositoryManager(String serverUrl, StringB
239259
Thread.sleep(500);
240260
}
241261
}
242-
String errorMessage = "Timed out connecting to " + serverUrl + " Output:\n" + outputBuffer
262+
String errorMessage = "Timed out connecting to " + serverUrl + " Output:\\n" + outputBuffer
243263
+ (lastException == null ? "" : ("\nLast error: " + lastException));
244264
fail(errorMessage);
245265
return null;

0 commit comments

Comments
 (0)