Skip to content

Commit 1f94b58

Browse files
committed
[ECO-5117][RTL13a] Fixed channel ATTACHING event detach err
1. Updated `attachWithTimeout` and `attachImpl` method to accept msgError param 2. Updated test assertions for spec RTL13a accordingly
1 parent a6bbcb2 commit 1f94b58

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/src/main/java/io/ably/lib/realtime/ChannelBase.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void attach(CompletionListener listener) throws AblyException {
194194

195195
void attach(boolean forceReattach, CompletionListener listener) {
196196
clearAttachTimers();
197-
attachWithTimeout(forceReattach, listener);
197+
attachWithTimeout(forceReattach, listener, null);
198198
}
199199

200200
/**
@@ -217,7 +217,7 @@ synchronized void transferQueuedPresenceMessages(List<QueuedMessage> messagesToT
217217

218218
private boolean attachResume;
219219

220-
private void attachImpl(final boolean forceReattach, final CompletionListener listener) throws AblyException {
220+
private void attachImpl(final boolean forceReattach, final CompletionListener listener, ErrorInfo reattachmentReason) throws AblyException {
221221
Log.v(TAG, "attach(); channel = " + name);
222222
if(!forceReattach) {
223223
/* check preconditions */
@@ -249,7 +249,7 @@ private void attachImpl(final boolean forceReattach, final CompletionListener li
249249
if (listener != null) {
250250
on(new ChannelStateCompletionListener(listener, ChannelState.attached, ChannelState.failed));
251251
}
252-
setState(ChannelState.attaching, null);
252+
setState(ChannelState.attaching, reattachmentReason);
253253
return;
254254
}
255255

@@ -277,7 +277,7 @@ private void attachImpl(final boolean forceReattach, final CompletionListener li
277277
attachMessage.setFlag(Flag.attach_resume);
278278
}
279279

280-
setState(ChannelState.attaching, null);
280+
setState(ChannelState.attaching, reattachmentReason);
281281
connectionManager.send(attachMessage, true, null);
282282
} catch(AblyException e) {
283283
throw e;
@@ -470,14 +470,14 @@ synchronized private void clearAttachTimers() {
470470
}
471471

472472
private void attachWithTimeout(final CompletionListener listener) throws AblyException {
473-
this.attachWithTimeout(false, listener);
473+
this.attachWithTimeout(false, listener, null);
474474
}
475475

476476
/**
477477
* Attach channel, if not attached within timeout set state to suspended and
478478
* set up timer to reattach it later
479479
*/
480-
synchronized private void attachWithTimeout(final boolean forceReattach, final CompletionListener listener) {
480+
synchronized private void attachWithTimeout(final boolean forceReattach, final CompletionListener listener, ErrorInfo reattachmentReason) {
481481
checkChannelIsNotReleased();
482482
Timer currentAttachTimer;
483483
try {
@@ -502,7 +502,7 @@ public void onError(ErrorInfo reason) {
502502
clearAttachTimers();
503503
callCompletionListenerError(listener, reason);
504504
}
505-
});
505+
}, reattachmentReason);
506506
} catch(AblyException e) {
507507
attachTimer = null;
508508
callCompletionListenerError(listener, e.errorInfo);
@@ -1303,7 +1303,7 @@ void onChannelMessage(ProtocolMessage msg) {
13031303
case suspended:
13041304
/* Unexpected detach, reattach immediately as per RTL13a */
13051305
Log.v(TAG, String.format(Locale.ROOT, "Server initiated detach for channel %s; attempting reattach", name));
1306-
attachWithTimeout(true, null);
1306+
attachWithTimeout(true, null, msg.error);
13071307
break;
13081308
case attaching:
13091309
/* RTL13b says we need to be suspended, but continue to retry */

lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,11 +1813,16 @@ public void server_initiated_detach_for_attached_channel() throws AblyException
18131813
ProtocolMessage detachedMessage = new ProtocolMessage() {{
18141814
action = Action.detached;
18151815
channel = channelName;
1816+
error = new ErrorInfo("Simulated detach", 40000);
18161817
}};
18171818
ably.connection.connectionManager.onMessage(null, detachedMessage);
18181819

18191820
/* Channel should transition to attaching, then to attached */
1820-
channelWaiter.waitFor(ChannelState.attaching);
1821+
ErrorInfo detachErr = channelWaiter.waitFor(ChannelState.attaching);
1822+
Assert.assertNotNull(detachErr);
1823+
Assert.assertEquals(40000, detachErr.code);
1824+
Assert.assertEquals("Simulated detach", detachErr.message);
1825+
18211826
channelWaiter.waitFor(ChannelState.attached);
18221827

18231828
List<ChannelState> channelStates = channelWaiter.getRecordedStates();
@@ -1869,11 +1874,16 @@ public void server_initiated_detach_for_suspended_channel() throws AblyException
18691874
ProtocolMessage detachedMessage = new ProtocolMessage() {{
18701875
action = Action.detached;
18711876
channel = channelName;
1877+
error = new ErrorInfo("Simulated detach", 40000);
18721878
}};
18731879
ably.connection.connectionManager.onMessage(null, detachedMessage);
18741880

18751881
/* Channel should transition to attaching, then to attached */
1876-
channelWaiter.waitFor(ChannelState.attaching);
1882+
ErrorInfo detachError = channelWaiter.waitFor(ChannelState.attaching);
1883+
Assert.assertNotNull(detachError);
1884+
Assert.assertEquals(40000, detachError.code);
1885+
Assert.assertEquals("Simulated detach", detachError.message);
1886+
18771887
channelWaiter.waitFor(ChannelState.attached);
18781888

18791889
List<ChannelState> channelStates = channelWaiter.getRecordedStates();

0 commit comments

Comments
 (0)