Skip to content

Commit

Permalink
test: fix random test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 26, 2021
1 parent 615942b commit 5b5b91c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/java/io/socket/client/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,28 @@ public void call(Object... objects) {
}
});

if (Manager.this._timeout >= 0) {
final long timeout = Manager.this._timeout;
final long timeout = Manager.this._timeout;
final Runnable onTimeout = new Runnable() {
@Override
public void run() {
logger.fine(String.format("connect attempt timed out after %d", timeout));
openSub.destroy();
socket.close();
socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout"));
}
};

if (timeout == 0) {
EventThread.exec(onTimeout);
return;
} else if (Manager.this._timeout > 0) {
logger.fine(String.format("connection attempt will timeout after %d", timeout));

final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
EventThread.exec(new Runnable() {
@Override
public void run() {
logger.fine(String.format("connect attempt timed out after %d", timeout));
openSub.destroy();
socket.close();
socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout"));
}
});
EventThread.exec(onTimeout);
}
}, timeout);

Expand Down

0 comments on commit 5b5b91c

Please sign in to comment.