Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ private Completable stop(String errorMessage) {
CompletableSubject subject = CompletableSubject.create();
startTask.onErrorComplete().subscribe(() ->
{
Completable stop = connectionState.transport.stop();
Transport transport = connectionState.transport;
Completable stop = (transport != null) ? transport.stop() : Completable.complete();
stop.subscribe(() -> subject.onComplete(), e -> subject.onError(e));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2783,6 +2783,32 @@ public void negotiateSentOnStart() {
assertEquals("http://example.com/negotiate?negotiateVersion=1", sentRequests.get(0).getUrl());
}

@Test
public void closeWithPendingNegotiate() {
SingleSubject<HttpResponse> responseSubject = SingleSubject.create();

TestHttpClient client = new TestHttpClient()
.on("POST", (req) -> responseSubject);

HubConnection hubConnection = HubConnectionBuilder
.create("http://example.com")
.withHttpClient(client)
.build();

Completable start = hubConnection.start();
assertEquals(HubConnectionState.CONNECTING, hubConnection.getConnectionState());

Completable stop = hubConnection.stop();

responseSubject.onSuccess(new HttpResponse(404, "", TestUtils.emptyByteBuffer));
stop.timeout(3, TimeUnit.SECONDS).blockingAwait();
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());

HttpRequestException exception = assertThrows(HttpRequestException.class, () -> start.blockingAwait(10, TimeUnit.SECONDS));
assertEquals("Unexpected status code returned from negotiate: 404 .", exception.getMessage());
assertEquals(404, exception.getStatusCode());
}

@Test
public void negotiateThatRedirectsForeverFailsAfter100Tries() {
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1",
Expand Down
Loading