Skip to content

Commit 6948352

Browse files
committed
Issue #13064 - Let test timeout if there is an issue.
Don't leave testing in stuck condition.
1 parent 165f90d commit 6948352

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.LinkedHashSet;
2828
import java.util.List;
2929
import java.util.Set;
30+
import java.util.concurrent.TimeUnit;
3031
import java.util.function.Predicate;
3132

3233
import org.eclipse.jetty.util.IO;
@@ -249,6 +250,18 @@ public void await() throws InterruptedException
249250
}
250251
}
251252

253+
// For test purposes only.
254+
protected boolean await(long time, TimeUnit unit) throws InterruptedException
255+
{
256+
try (AutoLock.WithCondition l = _lock.lock())
257+
{
258+
if (alive)
259+
return l.await(time, unit);
260+
else
261+
return true;
262+
}
263+
}
264+
252265
protected boolean isAlive()
253266
{
254267
try (AutoLock l = _lock.lock())

jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.OutputStream;
2121
import java.net.InetAddress;
2222
import java.net.Socket;
23+
import java.util.concurrent.TimeUnit;
2324

2425
import org.eclipse.jetty.util.thread.ShutdownThread;
2526
import org.junit.jupiter.api.AfterEach;
@@ -115,7 +116,7 @@ public void testStartStopDifferentPortDifferentKey() throws Exception
115116
monitor.start();
116117

117118
stop("stop", port, key, true);
118-
monitor.await();
119+
assertTrue(monitor.await(10, TimeUnit.SECONDS));
119120
assertTrue(!monitor.isAlive());
120121

121122
// Should be able to change port and key because it is stopped.
@@ -130,7 +131,7 @@ public void testStartStopDifferentPortDifferentKey() throws Exception
130131
assertTrue(monitor.isAlive());
131132

132133
stop("stop", port, key, true);
133-
monitor.await();
134+
assertTrue(monitor.await(5, TimeUnit.SECONDS));
134135
assertTrue(!monitor.isAlive());
135136
}
136137

@@ -166,7 +167,7 @@ public void testNoExitSystemProperty() throws Exception
166167
int port = monitor.getPort();
167168

168169
stop("stop", port, key, true);
169-
monitor.await();
170+
assertTrue(monitor.await(5, TimeUnit.SECONDS));
170171

171172
assertTrue(!monitor.isAlive());
172173
assertTrue(server.stopped);
@@ -230,7 +231,7 @@ public void testForceStopCommand() throws Exception
230231
int port = monitor.getPort();
231232

232233
stop("forcestop", port, key, true);
233-
monitor.await();
234+
assertTrue(monitor.await(5, TimeUnit.SECONDS));
234235

235236
assertTrue(!monitor.isAlive());
236237
assertTrue(server.stopped);
@@ -261,7 +262,7 @@ public void testOldStopCommandWithStopOnShutdownTrue() throws Exception
261262
int port = monitor.getPort();
262263

263264
stop("stop", port, key, true);
264-
monitor.await();
265+
assertTrue(monitor.await(5, TimeUnit.SECONDS));
265266

266267
assertTrue(!monitor.isAlive());
267268
assertTrue(server.stopped);
@@ -292,7 +293,7 @@ public void testOldStopCommandWithStopOnShutdownFalse() throws Exception
292293
int port = monitor.getPort();
293294

294295
stop("stop", port, key, true);
295-
monitor.await();
296+
assertTrue(monitor.await(5, TimeUnit.SECONDS));
296297

297298
assertTrue(!monitor.isAlive());
298299
assertTrue(!server.stopped);

0 commit comments

Comments
 (0)