1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Fix queueToDevice.spec.ts test flakiness (#2841)

This commit is contained in:
Michael Telatynski
2022-11-03 11:45:35 +00:00
committed by GitHub
parent d8f6449422
commit 0a35f2e2c7

View File

@@ -22,6 +22,7 @@ import { MatrixClient } from "../../src/client";
import { ToDeviceBatch } from '../../src/models/ToDeviceMessage'; import { ToDeviceBatch } from '../../src/models/ToDeviceMessage';
import { logger } from '../../src/logger'; import { logger } from '../../src/logger';
import { IStore } from '../../src/store'; import { IStore } from '../../src/store';
import { removeElement } from "../../src/utils";
const FAKE_USER = "@alice:example.org"; const FAKE_USER = "@alice:example.org";
const FAKE_DEVICE_ID = "AAAAAAAA"; const FAKE_DEVICE_ID = "AAAAAAAA";
@@ -75,6 +76,8 @@ describe.each([
let client: MatrixClient; let client: MatrixClient;
beforeEach(async function() { beforeEach(async function() {
jest.runOnlyPendingTimers();
jest.useRealTimers();
httpBackend = new MockHttpBackend(); httpBackend = new MockHttpBackend();
let store: IStore; let store: IStore;
@@ -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(); await flushPromises();
const dummyEvent = new MatrixEvent({ const dummyEvent = new MatrixEvent({
@@ -328,12 +331,12 @@ describe.each([
}); });
} }
const expectedCounts = [20, 1];
httpBackend.when( httpBackend.when(
"PUT", "/sendToDevice/org.example.foo/", "PUT", "/sendToDevice/org.example.foo/",
).check((request) => { ).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, {}); }).respond(200, {});
httpBackend.when( httpBackend.when(
"PUT", "/sendToDevice/org.example.foo/", "PUT", "/sendToDevice/org.example.foo/",
).check((request) => { ).check((request) => {