Try to make test more reliable (#12989)
This commit is contained in:
parent
5d4c4d648f
commit
7b7c13c0d5
|
|
@ -1273,18 +1273,22 @@ describe("HubConnection", () => {
|
||||||
const connection = new TestConnection();
|
const connection = new TestConnection();
|
||||||
const hubConnection = createHubConnection(connection, logger);
|
const hubConnection = createHubConnection(connection, logger);
|
||||||
try {
|
try {
|
||||||
hubConnection.serverTimeoutInMilliseconds = 400;
|
const timeoutInMilliseconds = 400;
|
||||||
|
hubConnection.serverTimeoutInMilliseconds = timeoutInMilliseconds;
|
||||||
|
|
||||||
const p = new PromiseSource<Error>();
|
const p = new PromiseSource<Error>();
|
||||||
hubConnection.onclose((e) => p.resolve(e));
|
hubConnection.onclose((e) => p.resolve(e));
|
||||||
|
|
||||||
await hubConnection.start();
|
await hubConnection.start();
|
||||||
|
|
||||||
for (let i = 0; i < 12; i++) {
|
const pingInterval = setInterval(async () => {
|
||||||
await pingAndWait(connection);
|
await connection.receive({ type: MessageType.Ping });
|
||||||
}
|
}, 10);
|
||||||
|
|
||||||
|
await delayUntil(timeoutInMilliseconds * 2);
|
||||||
|
|
||||||
await connection.stop();
|
await connection.stop();
|
||||||
|
clearInterval(pingInterval);
|
||||||
|
|
||||||
const error = await p.promise;
|
const error = await p.promise;
|
||||||
|
|
||||||
|
|
@ -1318,11 +1322,6 @@ describe("HubConnection", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function pingAndWait(connection: TestConnection): Promise<void> {
|
|
||||||
await connection.receive({ type: MessageType.Ping });
|
|
||||||
await delayUntil(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestProtocol implements IHubProtocol {
|
class TestProtocol implements IHubProtocol {
|
||||||
public readonly name: string = "TestProtocol";
|
public readonly name: string = "TestProtocol";
|
||||||
public readonly version: number = 1;
|
public readonly version: number = 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue