Skip to content

Commit

Permalink
Merge pull request #615 from marci4/master
Browse files Browse the repository at this point in the history
Test coverage for #609
  • Loading branch information
marci4 authored Nov 18, 2017
2 parents 70e0ab3 + a14b4f6 commit 2ff0047
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/test/java/org/java_websocket/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@Suite.SuiteClasses({
org.java_websocket.util.ByteBufferUtilsTest.class,
org.java_websocket.drafts.AllDraftTests.class,
org.java_websocket.issues.AllIssueTests.class,
org.java_websocket.misc.AllMiscTests.class,
org.java_websocket.protocols.AllProtocolTests.class,
org.java_websocket.framing.AllFramingTests.class
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/java_websocket/issues/AllIssueTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2010-2017 Nathan Rajlich
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.java_websocket.issues;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;


@RunWith(Suite.class)
@Suite.SuiteClasses({
org.java_websocket.issues.Issue609.class
})
/**
* Start all tests for issues
*/
public class AllIssueTests {
}
106 changes: 106 additions & 0 deletions src/test/java/org/java_websocket/issues/Issue609.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2010-2017 Nathan Rajlich
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.java_websocket.issues;

import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.server.WebSocketServer;
import org.junit.Test;

import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.CountDownLatch;

import static org.junit.Assert.assertTrue;

public class Issue609 {

CountDownLatch countDownLatch = new CountDownLatch( 1 );

boolean wasOpenClient;
boolean wasOpenServer;
@Test
public void testIssue() throws Exception {
WebSocketServer server = new WebSocketServer( new InetSocketAddress( 8887 ) ) {
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
}

@Override
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
wasOpenServer = conn.isOpen();
}

@Override
public void onMessage( WebSocket conn, String message ) {

}

@Override
public void onError( WebSocket conn, Exception ex ) {

}

@Override
public void onStart() {

}
};
server.start();
WebSocketClient webSocket = new WebSocketClient( new URI( "ws://localhost:8887" ) ) {
@Override
public void onOpen( ServerHandshake handshakedata ) {

}

@Override
public void onMessage( String message ) {

}

@Override
public void onClose( int code, String reason, boolean remote ) {
wasOpenClient= isOpen();
countDownLatch.countDown();
}

@Override
public void onError( Exception ex ) {

}
};
webSocket.connectBlocking();
assertTrue( webSocket.isOpen() );
webSocket.getSocket().close();
countDownLatch.await();
assertTrue( !webSocket.isOpen() );
assertTrue( !wasOpenClient );
assertTrue( !wasOpenServer );
server.stop();
}
}

0 comments on commit 2ff0047

Please sign in to comment.