Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed flaky tests caused by a race in websocket client's stop method
- Loading branch information
Zhen
committed
Dec 18, 2015
1 parent
0e69b03
commit 640ffe0
Showing
6 changed files
with
101 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...bolt/src/test/java/org/neo4j/bolt/v1/transport/socket/client/WebSocketConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.bolt.v1.transport.socket.client; | ||
|
||
import org.eclipse.jetty.websocket.client.WebSocketClient; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class WebSocketConnectionTest | ||
{ | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
@Test | ||
public void shouldNotThrowAnyExceptionWhenDataReceivedBeforeClose() throws Throwable | ||
{ | ||
// Given | ||
WebSocketClient client = mock( WebSocketClient.class ); | ||
WebSocketConnection conn = new WebSocketConnection( client ); | ||
when( client.isStopped() ).thenReturn( true ); | ||
|
||
byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
|
||
// When | ||
conn.onWebSocketBinary( data, 0, 10 ); | ||
conn.recv( 10 ); | ||
|
||
// Then | ||
// no exception | ||
} | ||
|
||
|
||
@Test | ||
public void shouldThrowIOExceptionWhenNotEnoughDataReceivedBeforeClose() throws Throwable | ||
{ | ||
// Given | ||
WebSocketClient client = mock( WebSocketClient.class ); | ||
WebSocketConnection conn = new WebSocketConnection( client ); | ||
when( client.isStopped() ).thenReturn( true, true ); | ||
|
||
byte[] data = {0, 1, 2, 3}; | ||
|
||
// When && Then | ||
conn.onWebSocketBinary( data, 0, 4 ); | ||
|
||
expectedException.expect( IOException.class ); | ||
expectedException.expectMessage( "Connection closed while waiting for data from the server." ); | ||
conn.recv( 10 ); | ||
} | ||
} |