Merge in 'release/5.0' changes

This commit is contained in:
dotnet-bot 2021-03-10 17:44:48 +00:00
commit e881191e91
2 changed files with 38 additions and 1 deletions

View File

@ -264,7 +264,13 @@ public class HubConnection implements AutoCloseable {
Transport transport = customTransport;
if (transport == null) {
Single<String> tokenProvider = negotiateResponse.getAccessToken() != null ? Single.just(negotiateResponse.getAccessToken()) : accessTokenProvider;
switch (negotiateResponse.getChosenTransport()) {
TransportEnum chosenTransport;
if (this.skipNegotiate) {
chosenTransport = this.transportEnum;
} else {
chosenTransport = negotiateResponse.getChosenTransport();
}
switch (chosenTransport) {
case LONG_POLLING:
transport = new LongPollingTransport(localHeaders, httpClient, tokenProvider);
break;

View File

@ -2743,6 +2743,37 @@ class HubConnectionTest {
assertNull(hubConnection.getConnectionId());
}
@Test
public void SkippingNegotiateDoesNotNegotiate() {
try (TestLogger logger = new TestLogger(WebSocketTransport.class.getName())) {
AtomicBoolean negotiateCalled = new AtomicBoolean(false);
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1",
(req) -> {
negotiateCalled.set(true);
return Single.just(new HttpResponse(200, "",
TestUtils.stringToByteBuffer("{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\""
+ "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}")));
});
HubConnection hubConnection = HubConnectionBuilder
.create("http://example")
.withTransport(TransportEnum.WEBSOCKETS)
.shouldSkipNegotiate(true)
.withHttpClient(client)
.build();
try {
hubConnection.start().timeout(30, TimeUnit.SECONDS).blockingAwait();
} catch (Exception e) {
assertEquals("WebSockets isn't supported in testing currently.", e.getMessage());
}
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
assertFalse(negotiateCalled.get());
logger.assertLog("Starting Websocket connection.");
}
}
@Test
public void connectionIdIsAvailableAfterStart() {
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate?negotiateVersion=1",