Skip to content

Commit f3d299f

Browse files
authored
Make Issue825Test more stable (TooTallNate#894)
Make Issue825Test more stable
2 parents 73c6805 + 6f1eeaa commit f3d299f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

‎src/test/java/org/java_websocket/issues/Issue825Test.java‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@
4949
importjava.util.concurrent.CountDownLatch;
5050

5151
publicclassIssue825Test{
52-
privateCountDownLatchcountClientDownLatch = newCountDownLatch(3);
53-
privateCountDownLatchcountServerDownLatch = newCountDownLatch(1);
52+
5453

5554
@Test(timeout = 15000)
5655
publicvoidtestIssue() throwsIOException, URISyntaxException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, CertificateException, InterruptedException{
56+
finalCountDownLatchcountClientOpenLatch = newCountDownLatch(3);
57+
finalCountDownLatchcountClientMessageLatch = newCountDownLatch(3);
58+
finalCountDownLatchcountServerDownLatch = newCountDownLatch(1);
5759
intport = SocketUtil.getAvailablePort();
5860
finalWebSocketClientwebSocket = newWebSocketClient(newURI("wss://localhost:" + port)){
5961
@Override
6062
publicvoidonOpen(ServerHandshakehandshakedata){
63+
countClientOpenLatch.countDown();
6164
}
6265

6366
@Override
@@ -72,7 +75,7 @@ public void onClose(int code, String reason, boolean remote){
7275
publicvoidonError(Exceptionex){
7376
}
7477
};
75-
WebSocketServerserver = newMyWebSocketServer(port, countServerDownLatch, countClientDownLatch);
78+
WebSocketServerserver = newMyWebSocketServer(port, countServerDownLatch, countClientMessageLatch);
7679

7780
// load up the key store
7881
StringSTORETYPE = "JKS";
@@ -109,23 +112,23 @@ public void onError(Exception ex){
109112
webSocket.closeBlocking();
110113
//Disconnect manually and reconnect
111114
webSocket.reconnect();
112-
Thread.sleep( 100);
115+
countClientOpenLatch.await();
113116
webSocket.send( "me" );
114117
Thread.sleep( 100 );
115118
webSocket.closeBlocking();
116-
countClientDownLatch.await();
119+
countClientMessageLatch.await();
117120
}
118121

119122

120123
privatestaticclassMyWebSocketServerextendsWebSocketServer{
121-
privatefinalCountDownLatchcountServerDownLatch;
122-
privatefinalCountDownLatchcountClientDownLatch;
124+
privatefinalCountDownLatchcountServerLatch;
125+
privatefinalCountDownLatchcountClientMessageLatch;
123126

124127

125-
publicMyWebSocketServer(intport, CountDownLatchserverDownLatch, CountDownLatchcountClientDownLatch){
128+
publicMyWebSocketServer(intport, CountDownLatchserverDownLatch, CountDownLatchcountClientMessageLatch){
126129
super(newInetSocketAddress(port));
127-
this.countServerDownLatch = serverDownLatch;
128-
this.countClientDownLatch = countClientDownLatch;
130+
this.countServerLatch = serverDownLatch;
131+
this.countClientMessageLatch = countClientMessageLatch;
129132
}
130133

131134
@Override
@@ -138,7 +141,7 @@ public void onClose(WebSocket conn, int code, String reason, boolean remote){
138141

139142
@Override
140143
publicvoidonMessage(WebSocketconn, Stringmessage){
141-
countClientDownLatch.countDown();
144+
countClientMessageLatch.countDown();
142145
}
143146

144147
@Override
@@ -148,7 +151,7 @@ public void onError(WebSocket conn, Exception ex){
148151

149152
@Override
150153
publicvoidonStart(){
151-
countServerDownLatch.countDown();
154+
countServerLatch.countDown();
152155
}
153156
}
154157
}

0 commit comments

Comments
(0)