Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,26 @@ public void negotiateSentOnStart() {
assertEquals("http://example.com/negotiate?negotiateVersion=1", sentRequests.get(0).getUrl());
}

@Test
public void closeWithPendingNegotiate() {
TestHttpClient client = new TestHttpClient()
.on("POST", (req) -> Single.just(new HttpResponse(404, "", TestUtils.emptyByteBuffer)).delay(200, TimeUnit.MILLISECONDS));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to set the Single's value after calling hubConnection.stop so we don't rely on delays as much?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, that is a good call. Made the change, and also checked that the bug would have been caught with the changed test.


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

Completable start = hubConnection.start();
assertEquals(HubConnectionState.CONNECTING, hubConnection.getConnectionState());
hubConnection.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