Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A AndroidAsync
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 333
    • Issues 333
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Koushik Dutta
  • AndroidAsync
  • Merge requests
  • !413
An error occurred while fetching the assigned milestone of the selected merge_request.

fixed the issue with the way handshake failure was handled in web socket futures

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/s-arash/master into master 9 years ago
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: s-arash

In creating web socket clients, if the handshake failed, the failure wouldn't be reported to the callback (it would be called with a null Exception parameter, and a null WebSocket paramter). Fixed that issue and created a test for it.

Compare
  • master (base)

and
  • latest version
    2cd731b5
    1 commit, 2 years ago

2 files
+ 61
- 1

    Preferences

    File browser
    Compare changes
Androi‎dAsync‎
src/com/koushik‎dutta/async/http‎
AsyncHttpC‎lient.java‎ +2 -1
test/src/com/koush‎ikdutta/async/test‎
IssueWithWebSocke‎tFuturesTests.java‎ +59 -0
AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java
+ 2
- 1
  • View file @ 2cd731b5

  • Edit in single-file editor

  • Open in Web IDE


@@ -688,7 +688,8 @@ public class AsyncHttpClient {
}
WebSocket ws = WebSocketImpl.finishHandshake(req.getHeaders(), response);
if (ws == null) {
if (!ret.setComplete(new WebSocketHandshakeException("Unable to complete websocket handshake")))
ex = new WebSocketHandshakeException("Unable to complete websocket handshake");
if (!ret.setComplete(ex))
return;
}
else {
AndroidAsync/test/src/com/koushikdutta/async/test/IssueWithWebSocketFuturesTests.java 0 → 100644
+ 59
- 0
  • View file @ 2cd731b5

  • Edit in single-file editor

  • Open in Web IDE

package com.koushikdutta.async.test;
import com.koushikdutta.async.future.Future;
import com.koushikdutta.async.http.AsyncHttpClient;
import com.koushikdutta.async.http.WebSocket;
import com.koushikdutta.async.http.server.AsyncHttpServer;
import com.koushikdutta.async.http.server.AsyncHttpServerRequest;
import junit.framework.TestCase;
import java.util.concurrent.CountDownLatch;
public class IssueWithWebSocketFuturesTests extends TestCase {
//testing that websocket callback gets called with the correct parameters.
public void testWebSocketFutureWithHandshakeFailureCallback() throws Exception {
//creating a faulty server!
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.websocket(".*", new AsyncHttpServer.WebSocketRequestCallback() {
@Override
public void onConnected(WebSocket webSocket, AsyncHttpServerRequest request) {
}
});
httpServer.listen(6666);
final Exception[] callbackException = {null};
final WebSocket[] callbackWs = {null};
final CountDownLatch countDownLatch = new CountDownLatch(1);
//for some reason, it fails with a WebSocketHandshakeException.
//But in general, if the handshake fails, the callback must be called with an exception.
Future<WebSocket> wsFuture = AsyncHttpClient.getDefaultInstance().websocket("ws://127.0.0.1:6666", "ws", new AsyncHttpClient.WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
callbackException[0] = ex;
callbackWs[0] = webSocket;
countDownLatch.countDown();
}
});
//wait for the future to complete
countDownLatch.await();
//exactly one mut be null
assertTrue(callbackWs[0] == null ^ callbackException[0] == null);
//callback parameters must be the same as the future's result
assertEquals(wsFuture.tryGet(), callbackWs[0]);
assertEquals(wsFuture.tryGetException(), callbackException[0]);
}
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference:
Source branch: github/fork/s-arash/master

Menu

Explore Projects Groups Snippets