Skip to content

Commit a14b4f6

Browse files
committed
Test coverage for TooTallNate#609
Fixes TooTallNate#613
1 parent 70e0ab3 commit a14b4f6

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

src/test/java/org/java_websocket/AllTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@Suite.SuiteClasses({
3434
org.java_websocket.util.ByteBufferUtilsTest.class,
3535
org.java_websocket.drafts.AllDraftTests.class,
36+
org.java_websocket.issues.AllIssueTests.class,
3637
org.java_websocket.misc.AllMiscTests.class,
3738
org.java_websocket.protocols.AllProtocolTests.class,
3839
org.java_websocket.framing.AllFramingTests.class
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.issues;
27+
import org.junit.runner.RunWith;
28+
import org.junit.runners.Suite;
29+
30+
31+
@RunWith(Suite.class)
32+
@Suite.SuiteClasses({
33+
org.java_websocket.issues.Issue609.class
34+
})
35+
/**
36+
* Start all tests for issues
37+
*/
38+
public class AllIssueTests {
39+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.issues;
27+
28+
import org.java_websocket.WebSocket;
29+
import org.java_websocket.client.WebSocketClient;
30+
import org.java_websocket.handshake.ClientHandshake;
31+
import org.java_websocket.handshake.ServerHandshake;
32+
import org.java_websocket.server.WebSocketServer;
33+
import org.junit.Test;
34+
35+
import java.net.InetSocketAddress;
36+
import java.net.URI;
37+
import java.util.concurrent.CountDownLatch;
38+
39+
import static org.junit.Assert.assertTrue;
40+
41+
public class Issue609 {
42+
43+
CountDownLatch countDownLatch = new CountDownLatch( 1 );
44+
45+
boolean wasOpenClient;
46+
boolean wasOpenServer;
47+
@Test
48+
public void testIssue() throws Exception {
49+
WebSocketServer server = new WebSocketServer( new InetSocketAddress( 8887 ) ) {
50+
@Override
51+
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
52+
}
53+
54+
@Override
55+
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
56+
wasOpenServer = conn.isOpen();
57+
}
58+
59+
@Override
60+
public void onMessage( WebSocket conn, String message ) {
61+
62+
}
63+
64+
@Override
65+
public void onError( WebSocket conn, Exception ex ) {
66+
67+
}
68+
69+
@Override
70+
public void onStart() {
71+
72+
}
73+
};
74+
server.start();
75+
WebSocketClient webSocket = new WebSocketClient( new URI( "ws://localhost:8887" ) ) {
76+
@Override
77+
public void onOpen( ServerHandshake handshakedata ) {
78+
79+
}
80+
81+
@Override
82+
public void onMessage( String message ) {
83+
84+
}
85+
86+
@Override
87+
public void onClose( int code, String reason, boolean remote ) {
88+
wasOpenClient= isOpen();
89+
countDownLatch.countDown();
90+
}
91+
92+
@Override
93+
public void onError( Exception ex ) {
94+
95+
}
96+
};
97+
webSocket.connectBlocking();
98+
assertTrue( webSocket.isOpen() );
99+
webSocket.getSocket().close();
100+
countDownLatch.await();
101+
assertTrue( !webSocket.isOpen() );
102+
assertTrue( !wasOpenClient );
103+
assertTrue( !wasOpenServer );
104+
server.stop();
105+
}
106+
}

0 commit comments

Comments
 (0)