Skip to content

Commit 1d04fc4

Browse files
committed
fix: integration tests for OkHttp realtime tests
1 parent 3aaeaca commit 1d04fc4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/src/main/java/io/ably/lib/transport/WebSocketTransport.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class WebSocketTransport implements ITransport {
5252
private ConnectListener connectListener;
5353
private WebSocketClient webSocketClient;
5454
private final WebSocketEngine webSocketEngine;
55+
private boolean activityCheckTurnedOff = false;
5556

5657
/******************
5758
* protected constructor
@@ -173,6 +174,16 @@ protected void preProcessReceivedMessage(ProtocolMessage message) {
173174
//Gives the chance to child classes to do message pre-processing
174175
}
175176

177+
/**
178+
* Visible For Testing
179+
* </p>
180+
* We need to turn off activity check for some tests (e.g. io.ably.lib.test.realtime.RealtimeConnectFailTest.disconnect_retry_channel_timeout_jitter_after_consistent_detach[binary_protocol])
181+
* Those tests expects that activity checks are passing, but protocol messages are not coming
182+
*/
183+
protected void turnOffActivityCheckIfPingListenerIsNotSupported() {
184+
if (!webSocketEngine.isPingListenerSupported()) activityCheckTurnedOff = true;
185+
}
186+
176187
public String toString() {
177188
return WebSocketTransport.class.getName() + " {" + getURL() + "}";
178189
}
@@ -319,7 +330,7 @@ private synchronized void dispose() {
319330
private synchronized void flagActivity() {
320331
lastActivityTime = System.currentTimeMillis();
321332
connectionManager.setLastActivity(lastActivityTime);
322-
if (activityTimerTask == null && connectionManager.maxIdleInterval != 0) {
333+
if (activityTimerTask == null && connectionManager.maxIdleInterval != 0 && !activityCheckTurnedOff) {
323334
/* No timer currently running because previously there was no
324335
* maxIdleInterval configured, but now there is a
325336
* maxIdleInterval configured. Call checkActivity so a timer

lib/src/test/java/io/ably/lib/test/util/MockWebsocketFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private MockWebsocketTransport(TransportParams givenTransportParams, TransportPa
155155
super(transformedTransportParams, connectionManager);
156156
this.givenTransportParams = givenTransportParams;
157157
this.transformedTransportParams = transformedTransportParams;
158+
turnOffActivityCheckIfPingListenerIsNotSupported();
158159
}
159160

160161
public List<ProtocolMessage> getSentMessages() {

0 commit comments

Comments
 (0)