Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky test fix #1346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Expand Up @@ -78,6 +78,7 @@ public class WebSocketImpl implements WebSocket {
*/
public static final int DEFAULT_PORT = 80;

private static volatile int executionCounter = 0;
/**
* The default wss port of WebSockets, as defined in the spec. If the nullary constructor is used,
* DEFAULT_WSS_PORT will be the port the WebSocketServer is binded to. Note that ports under 1024
Expand Down Expand Up @@ -569,6 +570,11 @@ public synchronized void closeConnection(int code, String message, boolean remot
}
handshakerequest = null;
readyState = ReadyState.CLOSED;
executionCounter += 1;
}

public static int getExecutionCounter() {
return executionCounter;
}

protected void closeConnection(int code, boolean remote) {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/java_websocket/issues/Issue677Test.java
Expand Up @@ -116,6 +116,9 @@ public void onStart() {
assertTrue("webSocket.isOpen()", webSocket0.isOpen());
webSocket0.close();
countDownLatch0.await();
while (org.java_websocket.WebSocketImpl.getExecutionCounter() < 2) {
Thread.yield();
}
assertTrue("webSocket.isClosed()", webSocket0.isClosed());
webSocket1.connectBlocking();
assertTrue("webSocket.isOpen()", webSocket1.isOpen());
Expand Down