Skip to content

Commit 0a35f2e

Browse files
authored
Fix queueToDevice.spec.ts test flakiness (#2841)
1 parent d8f6449 commit 0a35f2e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

spec/unit/queueToDevice.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { MatrixClient } from "../../src/client";
2222
import { ToDeviceBatch } from '../../src/models/ToDeviceMessage';
2323
import { logger } from '../../src/logger';
2424
import { IStore } from '../../src/store';
25+
import { removeElement } from "../../src/utils";
2526

2627
const FAKE_USER = "@alice:example.org";
2728
const FAKE_DEVICE_ID = "AAAAAAAA";
@@ -75,6 +76,8 @@ describe.each([
7576
let client: MatrixClient;
7677

7778
beforeEach(async function() {
79+
jest.runOnlyPendingTimers();
80+
jest.useRealTimers();
7881
httpBackend = new MockHttpBackend();
7982

8083
let store: IStore;
@@ -300,7 +303,7 @@ describe.each([
300303
],
301304
});
302305

303-
expect(await httpBackend.flush(undefined, 1, 1)).toEqual(1);
306+
expect(await httpBackend.flush(undefined, 1, 20)).toEqual(1);
304307
await flushPromises();
305308

306309
const dummyEvent = new MatrixEvent({
@@ -328,12 +331,12 @@ describe.each([
328331
});
329332
}
330333

334+
const expectedCounts = [20, 1];
331335
httpBackend.when(
332336
"PUT", "/sendToDevice/org.example.foo/",
333337
).check((request) => {
334-
expect(Object.keys(request.data.messages).length).toEqual(20);
338+
expect(removeElement(expectedCounts, c => c === Object.keys(request.data.messages).length)).toBeTruthy();
335339
}).respond(200, {});
336-
337340
httpBackend.when(
338341
"PUT", "/sendToDevice/org.example.foo/",
339342
).check((request) => {

0 commit comments

Comments
 (0)