Skip to content

Commit

Permalink
Fix queueToDevice.spec.ts test flakiness (#2841)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Nov 3, 2022
1 parent d8f6449 commit 0a35f2e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions spec/unit/queueToDevice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MatrixClient } from "../../src/client";
import { ToDeviceBatch } from '../../src/models/ToDeviceMessage';
import { logger } from '../../src/logger';
import { IStore } from '../../src/store';
import { removeElement } from "../../src/utils";

const FAKE_USER = "@alice:example.org";
const FAKE_DEVICE_ID = "AAAAAAAA";
Expand Down Expand Up @@ -75,6 +76,8 @@ describe.each([
let client: MatrixClient;

beforeEach(async function() {
jest.runOnlyPendingTimers();
jest.useRealTimers();
httpBackend = new MockHttpBackend();

let store: IStore;
Expand Down Expand Up @@ -300,7 +303,7 @@ describe.each([
],
});

expect(await httpBackend.flush(undefined, 1, 1)).toEqual(1);
expect(await httpBackend.flush(undefined, 1, 20)).toEqual(1);
await flushPromises();

const dummyEvent = new MatrixEvent({
Expand Down Expand Up @@ -328,12 +331,12 @@ describe.each([
});
}

const expectedCounts = [20, 1];
httpBackend.when(
"PUT", "/sendToDevice/org.example.foo/",
).check((request) => {
expect(Object.keys(request.data.messages).length).toEqual(20);
expect(removeElement(expectedCounts, c => c === Object.keys(request.data.messages).length)).toBeTruthy();
}).respond(200, {});

httpBackend.when(
"PUT", "/sendToDevice/org.example.foo/",
).check((request) => {
Expand Down

0 comments on commit 0a35f2e

Please sign in to comment.