test: fix random test failures

This commit is contained in:
Damien Arrachequesne
2021-04-26 09:12:55 +02:00
parent 615942b828
commit 5b5b91cb01

View File

@@ -271,15 +271,8 @@ public class Manager extends Emitter {
} }
}); });
if (Manager.this._timeout >= 0) {
final long timeout = Manager.this._timeout; final long timeout = Manager.this._timeout;
logger.fine(String.format("connection attempt will timeout after %d", timeout)); final Runnable onTimeout = new Runnable() {
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
EventThread.exec(new Runnable() {
@Override @Override
public void run() { public void run() {
logger.fine(String.format("connect attempt timed out after %d", timeout)); logger.fine(String.format("connect attempt timed out after %d", timeout));
@@ -287,7 +280,19 @@ public class Manager extends Emitter {
socket.close(); socket.close();
socket.emit(Engine.EVENT_ERROR, new SocketIOException("timeout")); 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(onTimeout);
} }
}, timeout); }, timeout);