Try to make test more reliable (#12989)

This commit is contained in:
Brennan 2019-08-11 20:23:18 -07:00 committed by GitHub
parent 5d4c4d648f
commit 7b7c13c0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 9 deletions

View File

@ -1273,18 +1273,22 @@ describe("HubConnection", () => {
const connection = new TestConnection();
const hubConnection = createHubConnection(connection, logger);
try {
hubConnection.serverTimeoutInMilliseconds = 400;
const timeoutInMilliseconds = 400;
hubConnection.serverTimeoutInMilliseconds = timeoutInMilliseconds;
const p = new PromiseSource<Error>();
hubConnection.onclose((e) => p.resolve(e));
await hubConnection.start();
for (let i = 0; i < 12; i++) {
await pingAndWait(connection);
}
const pingInterval = setInterval(async () => {
await connection.receive({ type: MessageType.Ping });
}, 10);
await delayUntil(timeoutInMilliseconds * 2);
await connection.stop();
clearInterval(pingInterval);
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 {
public readonly name: string = "TestProtocol";
public readonly version: number = 1;