From 0a35f2e2c74bca0cefc5d4f56f06765640d7a326 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 3 Nov 2022 11:45:35 +0000 Subject: [PATCH] Fix queueToDevice.spec.ts test flakiness (#2841) --- spec/unit/queueToDevice.spec.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/unit/queueToDevice.spec.ts b/spec/unit/queueToDevice.spec.ts index 4b3050a15..afdd7fdd5 100644 --- a/spec/unit/queueToDevice.spec.ts +++ b/spec/unit/queueToDevice.spec.ts @@ -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"; @@ -75,6 +76,8 @@ describe.each([ let client: MatrixClient; beforeEach(async function() { + jest.runOnlyPendingTimers(); + jest.useRealTimers(); httpBackend = new MockHttpBackend(); 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(); const dummyEvent = new MatrixEvent({ @@ -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) => {