Skip to content

Commit

Permalink
[UNDERTOW-1962] Sleep 1-2 seconds when stopping the server
Browse files Browse the repository at this point in the history
  • Loading branch information
fl4via committed Sep 27, 2021
1 parent 7fb00a9 commit b6d4903
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 2 deletions.
10 changes: 10 additions & 0 deletions core/src/test/java/io/undertow/client/http/AjpClientTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public static void beforeClass() throws IOException {
public static void afterClass() throws InterruptedException {
undertow.stop();
stopWorker(worker);
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

static UndertowClient createClient() {
Expand Down Expand Up @@ -218,6 +222,12 @@ public void failed(IOException e) {
}

} finally {
// add an extra sleep time to make sure we are not getting a BindException
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
undertow.start();
}

Expand Down
12 changes: 10 additions & 2 deletions core/src/test/java/io/undertow/server/StopTestCase.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package io.undertow.server;

import org.junit.After;
import org.junit.Test;
import org.xnio.Options;

import io.undertow.Undertow;

public class StopTestCase {

@After
public void waitServerStopCompletely() {
// sleep 1 s to prevent BindException (Address already in use) when running the tests
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

@Test
public void testStopUndertowNotStarted() {
Undertow.builder().build().stop();
Expand All @@ -18,8 +27,7 @@ public void testStopUndertowAfterExceptionDuringStart() {
Undertow undertow = Undertow.builder().setWorkerOption(Options.WORKER_IO_THREADS, -1).build();
try {
undertow.start();
}
catch (RuntimeException e) {
} catch (RuntimeException ignore) {
}
undertow.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
public static void stop() {
server.stop();
server = null;
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public void testProxy() throws Exception {
@AfterClass
public static void teardown() {
server1.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
}
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand All @@ -87,6 +91,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
}
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down Expand Up @@ -116,6 +124,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
}
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand All @@ -141,6 +153,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
}
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public void closed(ServerConnection connection) {
@AfterClass
public static void after() {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public int selectHost(LoadBalancingProxyClient.Host[] availableHosts) {
public static void teardown() {
server1.stop();
server2.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

// https://issues.jboss.org/browse/UNDERTOW-289
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public static void setup() throws Exception {
public static void teardown() throws Exception {
DefaultServer.stopSSLServer();
server.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}

}

private static void setProxyHandler(boolean rewriteHostHeader, boolean reuseXForwarded) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public class ProxyPathHandlingTest {
public void cleanup() {
targetServer.stop();
proxyServer.stop();
// add a 1s sleep time to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {

}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ static void stopServers() {
}
}
servers = null;
// sleep 2 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(2000);
} catch (InterruptedException ignore) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
public static void after() {
DefaultServer.setUndertowOptions(old);
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
@AfterClass
public static void stop() {
server.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public void failed(IOException e) {
} finally {
stopWorker(xnioWorker);
server.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ private void proxyProtocolRequestResponseCheck(String request, String expectedRe
Assert.assertTrue(result, result.contains(expectedResponse));
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the tests
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down Expand Up @@ -539,6 +543,10 @@ private void proxyProtocolRequestResponseCheck(byte[] request, String requestHtt
Assert.assertTrue(result, result.contains(expectedResponse));
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down Expand Up @@ -579,6 +587,10 @@ public void doTestProxyProtocolUnknown(String extra) throws Exception {
Assert.assertTrue(result, result.contains(expected));
} finally {
undertow.stop();
// sleep 1 s to prevent BindException (Address already in use) when restarting the server
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public void testRejection() {
} finally {
undertow.stop();
client.getConnectionManager().shutdown();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void testHang() throws IOException, GeneralSecurityException, Interrupted
doRequest(clientSslContext, address);

server.stop();
// sleep 1 s to prevent BindException (Address already in use) when running the CI
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {}
}

private void doRequest(SSLContext clientSslContext, InetSocketAddress address)
Expand Down

0 comments on commit b6d4903

Please sign in to comment.