File tree Expand file tree Collapse file tree 8 files changed +14
-9
lines changed
src/test/java/org/java_websocket Expand file tree Collapse file tree 8 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ public void test_ConnectBlockingCleanup() throws Throwable {
3434 public void run () {
3535 try {
3636 ServerSocket serverSocket = new ServerSocket (port );
37+ serverSocket .setReuseAddress (true );
3738 ready .countDown ();
3839 Socket clientSocket = serverSocket .accept ();
3940 accepted .countDown ();
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public class Issue713Test {
5050 CountDownLatch countDownLatchBytebuffer = new CountDownLatch (10 );
5151
5252 @ Test
53- public void testIllegalArgument () throws IOException {
53+ public void testIllegalArgument () throws InterruptedException {
5454 WebSocketServer server = new WebSocketServer (
5555 new InetSocketAddress (SocketUtil .getAvailablePort ())) {
5656 @ Override
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public class Issue834Test {
1717
1818 @ Test ()
1919 @ Timeout (1000 )
20- public void testNoNewThreads () throws IOException {
20+ public void testNoNewThreads () throws InterruptedException {
2121
2222 Set <Thread > threadSet1 = Thread .getAllStackTraces ().keySet ();
2323
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public class OpeningHandshakeRejectionTest {
5151 private static final String additionalHandshake = "Upgrade: websocket\r \n Connection: Upgrade\r \n \r \n " ;
5252
5353 @ BeforeEach
54- public void startServer () throws IOException {
54+ public void startServer () throws IOException , InterruptedException {
5555 port = SocketUtil .getAvailablePort ();
5656 thread = new Thread (
5757 new Runnable () {
@@ -218,6 +218,9 @@ public void testHandshakeRejectionTestCase11() throws Exception {
218218 }
219219
220220 private void testHandshakeRejection (int i ) throws Exception {
221+ do {
222+ Thread .sleep (100 );
223+ } while (serverSocket == null || !serverSocket .isBound ());
221224 final int finalI = i ;
222225 final CountDownLatch countDownLatch = new CountDownLatch (1 );
223226 WebSocketClient webSocketClient = new WebSocketClient (
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public class ProtocolHandshakeRejectionTest {
5858 private int port ;
5959
6060 @ BeforeEach
61- public void startServer () {
61+ public void startServer () throws InterruptedException {
6262 port = SocketUtil .getAvailablePort ();
6363 thread = new Thread (
6464 new Runnable () {
@@ -489,7 +489,7 @@ public void testHandshakeRejectionTestCase29() throws Exception {
489489
490490 private void testProtocolRejection (int i , Draft_6455 draft ) throws Exception {
491491 do {
492- Thread .sleep (10 );
492+ Thread .sleep (100 );
493493 } while (serverSocket == null || !serverSocket .isBound ());
494494 final int finalI = i ;
495495 final CountDownLatch countDownLatch = new CountDownLatch (1 );
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public class DaemonThreadTest {
1717
1818 @ Test ()
1919 @ Timeout (1000 )
20- public void test_AllCreatedThreadsAreDaemon () throws Throwable {
20+ public void test_AllCreatedThreadsAreDaemon () throws InterruptedException {
2121
2222 Set <Thread > threadSet1 = Thread .getAllStackTraces ().keySet ();
2323 final CountDownLatch ready = new CountDownLatch (1 );
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ public void testConstructor() {
110110
111111
112112 @ Test
113- public void testGetAddress () throws IOException {
113+ public void testGetAddress () throws InterruptedException {
114114 int port = SocketUtil .getAvailablePort ();
115115 InetSocketAddress inetSocketAddress = new InetSocketAddress (port );
116116 MyWebSocketServer server = new MyWebSocketServer (port );
Original file line number Diff line number Diff line change 3030
3131public class SocketUtil {
3232
33- public static int getAvailablePort () {
33+ public static int getAvailablePort () throws InterruptedException {
3434 while (true ) {
3535 try (ServerSocket srv = new ServerSocket (0 )) {
3636 return srv .getLocalPort ();
3737 } catch (IOException e ) {
38- // Ignore
38+ // Retry
39+ Thread .sleep (50 );
3940 }
4041 }
4142 }
You can’t perform that action at this time.
0 commit comments