Skip to content

Commit 5b5b91c

Browse files
test: fix random test failures
1 parent 615942b commit 5b5b91c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Diff for: src/main/java/io/socket/client/Manager.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,28 @@ public void call(Object... objects) {
271271
}
272272
});
273273

274-
if (Manager.this._timeout >= 0) {
275-
final long timeout = Manager.this._timeout;
274+
final long timeout = Manager.this._timeout;
275+
final Runnable onTimeout = new Runnable() {
276+
@Override
277+
public void run() {
278+
logger.fine(String.format("connect attempt timed out after %d", timeout));
279+
openSub.destroy();
280+
socket.close();
281+
socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout"));
282+
}
283+
};
284+
285+
if (timeout == 0) {
286+
EventThread.exec(onTimeout);
287+
return;
288+
} else if (Manager.this._timeout > 0) {
276289
logger.fine(String.format("connection attempt will timeout after %d", timeout));
277290

278291
final Timer timer = new Timer();
279292
timer.schedule(new TimerTask() {
280293
@Override
281294
public void run() {
282-
EventThread.exec(new Runnable() {
283-
@Override
284-
public void run() {
285-
logger.fine(String.format("connect attempt timed out after %d", timeout));
286-
openSub.destroy();
287-
socket.close();
288-
socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout"));
289-
}
290-
});
295+
EventThread.exec(onTimeout);
291296
}
292297
}, timeout);
293298

0 commit comments

Comments
 (0)