Repository navigation
fix: report error code 80017 for a closed connection #1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RaphaelFakhri
wants to merge
1
commit into
ably:main
Choose a base branch
from
RaphaelFakhri:fix/connection-closed-error-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/src/test/java/io/ably/lib/transport/ConnectionManagerClosedErrorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package io.ably.lib.transport; | ||
|
|
||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| import io.ably.lib.debug.DebugOptions; | ||
| import io.ably.lib.realtime.AblyRealtime; | ||
| import io.ably.lib.realtime.CompletionListener; | ||
| import io.ably.lib.realtime.ConnectionState; | ||
| import io.ably.lib.test.common.Helpers; | ||
| import io.ably.lib.test.util.MockWebsocketFactory; | ||
| import io.ably.lib.types.AblyException; | ||
| import io.ably.lib.types.ErrorInfo; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.junit.Test; | ||
|
|
||
| public class ConnectionManagerClosedErrorTest { | ||
|
|
||
| /** | ||
| * Closing the connection reports Ably code 80017 with HTTP status code 400, both in the | ||
| * state change and when attaching a channel afterwards. | ||
| */ | ||
| @Test | ||
| public void closed_connection_error_codes() throws AblyException { | ||
| DebugOptions options = new DebugOptions("appid.keyid:keysecret"); | ||
| options.autoConnect = false; | ||
| MockWebsocketFactory mockTransport = new MockWebsocketFactory(); | ||
| mockTransport.failConnect(); | ||
| options.transportFactory = mockTransport; | ||
|
|
||
| try (AblyRealtime ably = new AblyRealtime(options)) { | ||
| Helpers.ConnectionWaiter connectionWaiter = new Helpers.ConnectionWaiter(ably.connection); | ||
| ably.connection.connect(); | ||
| assertThat(connectionWaiter.waitFor(ConnectionState.disconnected, 1, 10000), is(true)); | ||
| ably.connection.close(); | ||
| assertThat(connectionWaiter.waitFor(ConnectionState.closed, 1, 10000), is(true)); | ||
|
|
||
| ErrorInfo closedReason = connectionWaiter.lastStateChange().reason; | ||
| assertThat(closedReason, is(notNullValue())); | ||
| assertThat(closedReason.code, is(80017)); | ||
| assertThat(closedReason.statusCode, is(400)); | ||
|
|
||
| AtomicReference<ErrorInfo> attachError = new AtomicReference<>(); | ||
| ably.channels.get("closed_connection_attach").attach(new CompletionListener() { | ||
| @Override | ||
| public void onSuccess() {} | ||
|
|
||
| @Override | ||
| public void onError(ErrorInfo reason) { | ||
| attachError.set(reason); | ||
| } | ||
| }); | ||
| assertThat(attachError.get(), is(notNullValue())); | ||
| assertThat(attachError.get().code, is(80017)); | ||
| assertThat(attachError.get().statusCode, is(400)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The synchronous throw happens in
attachImpl, but the publicattach(CompletionListener)andattach()don't expose it. Both callattach(false, listener), which goes throughattachWithTimeout. That method catches theAblyExceptionfromattachImpland passes it tocallCompletionListenerError, so the listener'sonErrorruns on the calling thread beforeattachreturns.The test keeps the listener form for this reason. Without the source change, it fails on the first assertion (
80017). With the change, it passes. The test stays as is.