Skip to content

Commit 7b7c13c

Browse files
Try to make test more reliable (#12989)
1 parent 5d4c4d6 commit 7b7c13c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/SignalR/clients/ts/signalr/tests/HubConnection.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,18 +1273,22 @@ describe("HubConnection", () => {
12731273
const connection = new TestConnection();
12741274
const hubConnection = createHubConnection(connection, logger);
12751275
try {
1276-
hubConnection.serverTimeoutInMilliseconds = 400;
1276+
const timeoutInMilliseconds = 400;
1277+
hubConnection.serverTimeoutInMilliseconds = timeoutInMilliseconds;
12771278

12781279
const p = new PromiseSource<Error>();
12791280
hubConnection.onclose((e) => p.resolve(e));
12801281

12811282
await hubConnection.start();
12821283

1283-
for (let i = 0; i < 12; i++) {
1284-
await pingAndWait(connection);
1285-
}
1284+
const pingInterval = setInterval(async () => {
1285+
await connection.receive({ type: MessageType.Ping });
1286+
}, 10);
1287+
1288+
await delayUntil(timeoutInMilliseconds * 2);
12861289

12871290
await connection.stop();
1291+
clearInterval(pingInterval);
12881292

12891293
const error = await p.promise;
12901294

@@ -1318,11 +1322,6 @@ describe("HubConnection", () => {
13181322
});
13191323
});
13201324

1321-
async function pingAndWait(connection: TestConnection): Promise<void> {
1322-
await connection.receive({ type: MessageType.Ping });
1323-
await delayUntil(50);
1324-
}
1325-
13261325
class TestProtocol implements IHubProtocol {
13271326
public readonly name: string = "TestProtocol";
13281327
public readonly version: number = 1;

0 commit comments

Comments
 (0)