Skip to content

Commit

Permalink
Change expected onError behaviour
Browse files Browse the repository at this point in the history
Java-WebSocket will call onError when an exception occurs, then onClose.
Changing the pusher-java-client behaviour so that it doesn't change the
connection state to DISCONNECTED onError, but waits for onClose.
  • Loading branch information
leggetter committed Apr 10, 2013
1 parent b65da17 commit 233236f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ public void onError(final Exception ex) {

Factory.getEventQueue().execute(new Runnable() {
public void run() {
updateState(ConnectionState.DISCONNECTED);
// Do not change connection state as Java_WebSocket will also call onClose.
// See: https://github.com/leggetter/pusher-java-client/issues/8#issuecomment-16128590
//updateState(ConnectionState.DISCONNECTED);
sendErrorToAllListeners("An exception was thrown by the websocket",
null, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,14 @@ public void testOnCloseCallbackDoesNotCallListenerIfItIsNotBoundToDisconnectedEv
}

@Test
public void testOnErrorCallbackUpdatesStateToDisconnectedAndRaisesErrorEvent() {
public void testOnErrorCallbackRaisesErrorEvent() {
connection.connect();
verify(mockEventListener).onConnectionStateChange(
new ConnectionStateChange(ConnectionState.DISCONNECTED,
ConnectionState.CONNECTING));

Exception e = new Exception();
connection.onError(e);
verify(mockEventListener).onConnectionStateChange(
new ConnectionStateChange(ConnectionState.CONNECTING,
ConnectionState.DISCONNECTED));
verify(mockEventListener).onError(
"An exception was thrown by the websocket", null, e);
}
Expand Down

0 comments on commit 233236f

Please sign in to comment.