Move TS tests to async and fix some test log leaking (#21076)
This commit is contained in:
parent
be76a0322c
commit
da1a721003
|
|
@ -9,12 +9,13 @@ import { FetchHttpClient } from "@microsoft/signalr/dist/esm/FetchHttpClient";
|
||||||
import { Platform } from "@microsoft/signalr/dist/esm/Utils";
|
import { Platform } from "@microsoft/signalr/dist/esm/Utils";
|
||||||
import { XhrHttpClient } from "@microsoft/signalr/dist/esm/XhrHttpClient";
|
import { XhrHttpClient } from "@microsoft/signalr/dist/esm/XhrHttpClient";
|
||||||
|
|
||||||
// On slower CI machines, these tests sometimes take longer than 5s
|
export let DEFAULT_TIMEOUT_INTERVAL: number = 40 * 1000;
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20 * 1000;
|
|
||||||
|
|
||||||
export let ENDPOINT_BASE_URL: string = "";
|
export let ENDPOINT_BASE_URL: string = "";
|
||||||
export let ENDPOINT_BASE_HTTPS_URL: string = "";
|
export let ENDPOINT_BASE_HTTPS_URL: string = "";
|
||||||
|
|
||||||
|
// On slower CI machines, these tests sometimes take longer than 5s
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
|
||||||
if (typeof window !== "undefined" && (window as any).__karma__) {
|
if (typeof window !== "undefined" && (window as any).__karma__) {
|
||||||
const args = (window as any).__karma__.config.args as string[];
|
const args = (window as any).__karma__.config.args as string[];
|
||||||
let httpsServer = "";
|
let httpsServer = "";
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// tslint:disable:no-floating-promises
|
// tslint:disable:no-floating-promises
|
||||||
|
|
||||||
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr";
|
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr";
|
||||||
import { eachHttpClient, eachTransport, ECHOENDPOINT_URL } from "./Common";
|
import { DEFAULT_TIMEOUT_INTERVAL, eachHttpClient, eachTransport, ECHOENDPOINT_URL } from "./Common";
|
||||||
import { TestLogger } from "./TestLogger";
|
import { TestLogger } from "./TestLogger";
|
||||||
|
|
||||||
// We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file.
|
// We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file.
|
||||||
|
|
@ -13,6 +13,8 @@ import { HttpConnection } from "@microsoft/signalr/dist/esm/HttpConnection";
|
||||||
import { Platform } from "@microsoft/signalr/dist/esm/Utils";
|
import { Platform } from "@microsoft/signalr/dist/esm/Utils";
|
||||||
import "./LogBannerReporter";
|
import "./LogBannerReporter";
|
||||||
|
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
|
||||||
const commonOptions: IHttpConnectionOptions = {
|
const commonOptions: IHttpConnectionOptions = {
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
logger: TestLogger.instance,
|
logger: TestLogger.instance,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { AbortError, DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, H
|
||||||
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
|
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
|
||||||
import { getUserAgentHeader, Platform } from "@microsoft/signalr/dist/esm/Utils";
|
import { getUserAgentHeader, Platform } from "@microsoft/signalr/dist/esm/Utils";
|
||||||
|
|
||||||
import { eachTransport, eachTransportAndProtocolAndHttpClient, ENDPOINT_BASE_HTTPS_URL, ENDPOINT_BASE_URL } from "./Common";
|
import { DEFAULT_TIMEOUT_INTERVAL, eachTransport, eachTransportAndProtocolAndHttpClient, ENDPOINT_BASE_HTTPS_URL, ENDPOINT_BASE_URL } from "./Common";
|
||||||
import "./LogBannerReporter";
|
import "./LogBannerReporter";
|
||||||
import { TestLogger } from "./TestLogger";
|
import { TestLogger } from "./TestLogger";
|
||||||
|
|
||||||
|
|
@ -22,6 +22,8 @@ const TESTHUBENDPOINT_HTTPS_URL = ENDPOINT_BASE_HTTPS_URL ? (ENDPOINT_BASE_HTTPS
|
||||||
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets";
|
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets";
|
||||||
const TESTHUB_REDIRECT_ENDPOINT_URL = ENDPOINT_BASE_URL + "/redirect?numRedirects=0&baseUrl=" + ENDPOINT_BASE_URL;
|
const TESTHUB_REDIRECT_ENDPOINT_URL = ENDPOINT_BASE_URL + "/redirect?numRedirects=0&baseUrl=" + ENDPOINT_BASE_URL;
|
||||||
|
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
|
||||||
const commonOptions: IHttpConnectionOptions = {
|
const commonOptions: IHttpConnectionOptions = {
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
};
|
};
|
||||||
|
|
@ -52,7 +54,7 @@ function getConnectionBuilder(transportType?: HttpTransportType, url?: string, o
|
||||||
describe("hubConnection", () => {
|
describe("hubConnection", () => {
|
||||||
eachTransportAndProtocolAndHttpClient((transportType, protocol, httpClient) => {
|
eachTransportAndProtocolAndHttpClient((transportType, protocol, httpClient) => {
|
||||||
describe("using " + protocol.name + " over " + HttpTransportType[transportType] + " transport", () => {
|
describe("using " + protocol.name + " over " + HttpTransportType[transportType] + " transport", () => {
|
||||||
it("can invoke server method and receive result", (done) => {
|
it("can invoke server method and receive result", async (done) => {
|
||||||
const message = "你好,世界!";
|
const message = "你好,世界!";
|
||||||
|
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
|
|
@ -64,22 +66,16 @@ describe("hubConnection", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("Echo", message).then((result) => {
|
const result = await hubConnection.invoke("Echo", message);
|
||||||
expect(result).toBe(message);
|
expect(result).toBe(message);
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
await hubConnection.stop();
|
||||||
}).then(() => {
|
done();
|
||||||
hubConnection.stop();
|
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (shouldRunHttpsTests) {
|
if (shouldRunHttpsTests) {
|
||||||
it("using https, can invoke server method and receive result", (done) => {
|
it("using https, can invoke server method and receive result", async (done) => {
|
||||||
const message = "你好,世界!";
|
const message = "你好,世界!";
|
||||||
|
|
||||||
const hubConnection = getConnectionBuilder(transportType, TESTHUBENDPOINT_HTTPS_URL, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, TESTHUBENDPOINT_HTTPS_URL, { httpClient })
|
||||||
|
|
@ -91,22 +87,16 @@ describe("hubConnection", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("Echo", message).then((result) => {
|
const result = await hubConnection.invoke("Echo", message);
|
||||||
expect(result).toBe(message);
|
expect(result).toBe(message);
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
await hubConnection.stop();
|
||||||
}).then(() => {
|
done();
|
||||||
hubConnection.stop();
|
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it("can invoke server method non-blocking and not receive result", (done) => {
|
it("can invoke server method non-blocking and not receive result", async (done) => {
|
||||||
const message = "你好,世界!";
|
const message = "你好,世界!";
|
||||||
|
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
|
|
@ -118,19 +108,14 @@ describe("hubConnection", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.send("Echo", message).catch((e) => {
|
await hubConnection.send("Echo", message);
|
||||||
fail(e);
|
|
||||||
}).then(() => {
|
await hubConnection.stop();
|
||||||
hubConnection.stop();
|
done();
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can invoke server method structural object and receive structural result", (done) => {
|
it("can invoke server method structural object and receive structural result", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -146,15 +131,11 @@ describe("hubConnection", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.send("SendCustomObject", { Name: "test", Value: 42 });
|
await hubConnection.send("SendCustomObject", { Name: "test", Value: 42 });
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can stream server method and receive result", (done) => {
|
it("can stream server method and receive result", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -165,27 +146,23 @@ describe("hubConnection", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const received: string[] = [];
|
const received: string[] = [];
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.stream<string>("Stream").subscribe({
|
hubConnection.stream<string>("Stream").subscribe({
|
||||||
complete() {
|
async complete() {
|
||||||
expect(received).toEqual(["a", "b", "c"]);
|
expect(received).toEqual(["a", "b", "c"]);
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
},
|
},
|
||||||
error(err) {
|
async error(err) {
|
||||||
fail(err);
|
fail(err);
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
},
|
},
|
||||||
next(item) {
|
next(item) {
|
||||||
received.push(item);
|
received.push(item);
|
||||||
},
|
},
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can stream server method and cancel stream", (done) => {
|
it("can stream server method and cancel stream", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -195,152 +172,130 @@ describe("hubConnection", () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.on("StreamCanceled", () => {
|
hubConnection.on("StreamCanceled", async () => {
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
const subscription = hubConnection.stream<string>("InfiniteStream").subscribe({
|
const subscription = hubConnection.stream<string>("InfiniteStream").subscribe({
|
||||||
complete() {
|
complete() {
|
||||||
},
|
},
|
||||||
error(err) {
|
async error(err) {
|
||||||
fail(err);
|
fail(err);
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
},
|
},
|
||||||
next() {
|
next() {
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
subscription.dispose();
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
subscription.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rethrows an exception from the server when invoking", (done) => {
|
it("rethrows an exception from the server when invoking", async (done) => {
|
||||||
const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred.";
|
const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred.";
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("ThrowException", "An error occurred.").then(() => {
|
try {
|
||||||
// exception expected but none thrown
|
await hubConnection.invoke("ThrowException", "An error occurred.");
|
||||||
fail();
|
// exception expected but none thrown
|
||||||
}).catch((e) => {
|
fail();
|
||||||
expect(e.message).toBe(errorMessage);
|
} catch (e) {
|
||||||
}).then(() => {
|
expect(e.message).toBe(errorMessage);
|
||||||
return hubConnection.stop();
|
}
|
||||||
}).then(() => {
|
|
||||||
done();
|
await hubConnection.stop();
|
||||||
});
|
done();
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when invoking streaming method with invoke", (done) => {
|
it("throws an exception when invoking streaming method with invoke", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("EmptyStream").then(() => {
|
|
||||||
// exception expected but none thrown
|
try {
|
||||||
fail();
|
await hubConnection.invoke("EmptyStream");
|
||||||
}).catch((e) => {
|
// exception expected but none thrown
|
||||||
expect(e.message).toBe("The client attempted to invoke the streaming 'EmptyStream' method with a non-streaming invocation.");
|
fail();
|
||||||
}).then(() => {
|
} catch (e) {
|
||||||
return hubConnection.stop();
|
expect(e.message).toBe("The client attempted to invoke the streaming 'EmptyStream' method with a non-streaming invocation.");
|
||||||
}).then(() => {
|
}
|
||||||
done();
|
|
||||||
});
|
await hubConnection.stop();
|
||||||
}).catch((e) => {
|
done();
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when receiving a streaming result for method called with invoke", (done) => {
|
it("throws an exception when receiving a streaming result for method called with invoke", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("Stream").then(() => {
|
|
||||||
// exception expected but none thrown
|
try {
|
||||||
fail();
|
await hubConnection.invoke("Stream");
|
||||||
}).catch((e) => {
|
// exception expected but none thrown
|
||||||
expect(e.message).toBe("The client attempted to invoke the streaming 'Stream' method with a non-streaming invocation.");
|
fail();
|
||||||
}).then(() => {
|
} catch (e) {
|
||||||
return hubConnection.stop();
|
expect(e.message).toBe("The client attempted to invoke the streaming 'Stream' method with a non-streaming invocation.");
|
||||||
}).then(() => {
|
}
|
||||||
done();
|
|
||||||
});
|
await hubConnection.stop();
|
||||||
}).catch((e) => {
|
done();
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rethrows an exception from the server when streaming", (done) => {
|
it("rethrows an exception from the server when streaming", async (done) => {
|
||||||
const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred.";
|
const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred.";
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.stream("StreamThrowException", "An error occurred.").subscribe({
|
hubConnection.stream("StreamThrowException", "An error occurred.").subscribe({
|
||||||
complete() {
|
async complete() {
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
fail();
|
fail();
|
||||||
},
|
},
|
||||||
error(err) {
|
async error(err) {
|
||||||
expect(err.message).toEqual(errorMessage);
|
expect(err.message).toEqual(errorMessage);
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
next() {
|
async next() {
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
fail();
|
fail();
|
||||||
},
|
},
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws an exception when invoking hub method with stream", (done) => {
|
it("throws an exception when invoking hub method with stream", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.stream("Echo", "42").subscribe({
|
hubConnection.stream("Echo", "42").subscribe({
|
||||||
complete() {
|
async complete() {
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
fail();
|
fail();
|
||||||
},
|
},
|
||||||
error(err) {
|
async error(err) {
|
||||||
expect(err.message).toEqual("The client attempted to invoke the non-streaming 'Echo' method with a streaming invocation.");
|
expect(err.message).toEqual("The client attempted to invoke the non-streaming 'Echo' method with a streaming invocation.");
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
next() {
|
async next() {
|
||||||
hubConnection.stop();
|
await hubConnection.stop();
|
||||||
fail();
|
fail();
|
||||||
},
|
},
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can receive server calls", (done) => {
|
it("can receive server calls", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -352,25 +307,22 @@ describe("hubConnection", () => {
|
||||||
const idx = Math.floor(Math.random() * (methodName.length - 1));
|
const idx = Math.floor(Math.random() * (methodName.length - 1));
|
||||||
methodName = methodName.substr(0, idx) + methodName[idx].toUpperCase() + methodName.substr(idx + 1);
|
methodName = methodName.substr(0, idx) + methodName[idx].toUpperCase() + methodName.substr(idx + 1);
|
||||||
|
|
||||||
|
const receivePromise = new PromiseSource<string>();
|
||||||
hubConnection.on(methodName, (msg) => {
|
hubConnection.on(methodName, (msg) => {
|
||||||
expect(msg).toBe(message);
|
receivePromise.resolve(msg);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start()
|
await hubConnection.start();
|
||||||
.then(() => {
|
await hubConnection.invoke("InvokeWithString", message);
|
||||||
return hubConnection.invoke("InvokeWithString", message);
|
|
||||||
})
|
const receiveMsg = await receivePromise;
|
||||||
.then(() => {
|
expect(receiveMsg).toBe(message);
|
||||||
return hubConnection.stop();
|
|
||||||
})
|
await hubConnection.stop();
|
||||||
.catch((e) => {
|
done();
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can receive server calls without rebinding handler when restarted", (done) => {
|
it("can receive server calls without rebinding handler when restarted", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -385,22 +337,14 @@ describe("hubConnection", () => {
|
||||||
let closeCount = 0;
|
let closeCount = 0;
|
||||||
let invocationCount = 0;
|
let invocationCount = 0;
|
||||||
|
|
||||||
hubConnection.onclose((e) => {
|
hubConnection.onclose(async (e) => {
|
||||||
expect(e).toBeUndefined();
|
expect(e).toBeUndefined();
|
||||||
closeCount += 1;
|
closeCount += 1;
|
||||||
if (closeCount === 1) {
|
if (closeCount === 1) {
|
||||||
// Reconnect
|
// Reconnect
|
||||||
hubConnection.start()
|
await hubConnection.start();
|
||||||
.then(() => {
|
await hubConnection.invoke("InvokeWithString", message);
|
||||||
return hubConnection.invoke("InvokeWithString", message);
|
await hubConnection.stop();
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return hubConnection.stop();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
fail(error);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
expect(invocationCount).toBe(2);
|
expect(invocationCount).toBe(2);
|
||||||
done();
|
done();
|
||||||
|
|
@ -412,17 +356,9 @@ describe("hubConnection", () => {
|
||||||
invocationCount += 1;
|
invocationCount += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start()
|
await hubConnection.start();
|
||||||
.then(() => {
|
await hubConnection.invoke("InvokeWithString", message);
|
||||||
return hubConnection.invoke("InvokeWithString", message);
|
await hubConnection.stop();
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return hubConnection.stop();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("closed with error or start fails if hub cannot be created", async (done) => {
|
it("closed with error or start fails if hub cannot be created", async (done) => {
|
||||||
|
|
@ -446,7 +382,7 @@ describe("hubConnection", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can handle different types", (done) => {
|
it("can handle different types", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -468,28 +404,19 @@ describe("hubConnection", () => {
|
||||||
String: "Hello, World!",
|
String: "Hello, World!",
|
||||||
};
|
};
|
||||||
|
|
||||||
hubConnection.start()
|
await hubConnection.start();
|
||||||
.then(() => {
|
const value = await hubConnection.invoke("EchoComplexObject", complexObject);
|
||||||
return hubConnection.invoke("EchoComplexObject", complexObject);
|
if (protocol.name === "messagepack") {
|
||||||
})
|
// msgpack5 creates a Buffer for byte arrays and jasmine fails to compare a Buffer
|
||||||
.then((value) => {
|
// and a Uint8Array even though Buffer instances are also Uint8Array instances
|
||||||
if (protocol.name === "messagepack") {
|
value.ByteArray = new Uint8Array(value.ByteArray);
|
||||||
// msgpack5 creates a Buffer for byte arrays and jasmine fails to compare a Buffer
|
}
|
||||||
// and a Uint8Array even though Buffer instances are also Uint8Array instances
|
expect(value).toEqual(complexObject);
|
||||||
value.ByteArray = new Uint8Array(value.ByteArray);
|
|
||||||
}
|
await hubConnection.stop();
|
||||||
expect(value).toEqual(complexObject);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
hubConnection.stop();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can receive different types", (done) => {
|
it("can receive different types", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
.withHubProtocol(protocol)
|
.withHubProtocol(protocol)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -511,28 +438,19 @@ describe("hubConnection", () => {
|
||||||
String: "hello world",
|
String: "hello world",
|
||||||
};
|
};
|
||||||
|
|
||||||
hubConnection.start()
|
await hubConnection.start();
|
||||||
.then(() => {
|
const value = await hubConnection.invoke("SendComplexObject");
|
||||||
return hubConnection.invoke("SendComplexObject");
|
if (protocol.name === "messagepack") {
|
||||||
})
|
// msgpack5 creates a Buffer for byte arrays and jasmine fails to compare a Buffer
|
||||||
.then((value) => {
|
// and a Uint8Array even though Buffer instances are also Uint8Array instances
|
||||||
if (protocol.name === "messagepack") {
|
value.ByteArray = new Uint8Array(value.ByteArray);
|
||||||
// msgpack5 creates a Buffer for byte arrays and jasmine fails to compare a Buffer
|
}
|
||||||
// and a Uint8Array even though Buffer instances are also Uint8Array instances
|
expect(value).toEqual(complexObject);
|
||||||
value.ByteArray = new Uint8Array(value.ByteArray);
|
|
||||||
}
|
await hubConnection.stop();
|
||||||
expect(value).toEqual(complexObject);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
hubConnection.stop();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can be restarted", (done) => {
|
it("can be restarted", async (done) => {
|
||||||
const message = "你好,世界!";
|
const message = "你好,世界!";
|
||||||
|
|
||||||
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient })
|
||||||
|
|
@ -540,41 +458,26 @@ describe("hubConnection", () => {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let closeCount = 0;
|
let closeCount = 0;
|
||||||
hubConnection.onclose((error) => {
|
hubConnection.onclose(async (error) => {
|
||||||
expect(error).toBe(undefined);
|
expect(error).toBe(undefined);
|
||||||
|
|
||||||
// Start and invoke again
|
// Start and invoke again
|
||||||
if (closeCount === 0) {
|
if (closeCount === 0) {
|
||||||
closeCount += 1;
|
closeCount += 1;
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("Echo", message).then((result) => {
|
const value = await hubConnection.invoke("Echo", message);
|
||||||
expect(result).toBe(message);
|
expect(value).toBe(message);
|
||||||
}).catch((e) => {
|
await hubConnection.stop();
|
||||||
fail(e);
|
|
||||||
}).then(() => {
|
|
||||||
hubConnection.stop();
|
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
hubConnection.start().then(() => {
|
await hubConnection.start();
|
||||||
hubConnection.invoke("Echo", message).then((result) => {
|
const result = await hubConnection.invoke("Echo", message);
|
||||||
expect(result).toBe(message);
|
expect(result).toBe(message);
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
await hubConnection.stop();
|
||||||
}).then(() => {
|
|
||||||
hubConnection.stop();
|
|
||||||
});
|
|
||||||
}).catch((e) => {
|
|
||||||
fail(e);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can stream from client to server with rxjs", async (done) => {
|
it("can stream from client to server with rxjs", async (done) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue