Fix CI test flake for AttachmentDownloadManager

This commit is contained in:
trevor-signal 2024-08-06 16:56:52 -04:00 committed by GitHub
parent 9a9f9495f1
commit 31bcb1e4cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -157,18 +157,22 @@ describe('AttachmentDownloadManager/JobManager', () => {
); );
} }
async function flushSQLReads() {
await DataWriter.getNextAttachmentDownloadJobs({ limit: 10 });
}
async function advanceTime(ms: number) { async function advanceTime(ms: number) {
// When advancing the timers, we want to make sure any DB operations are completed // When advancing the timers, we want to make sure any DB operations are completed
// first. In cases like maybeStartJobs where we prevent re-entrancy, without this, // first. In cases like maybeStartJobs where we prevent re-entrancy, without this,
// prior (unfinished) invocations can prevent subsequent calls after the clock is // prior (unfinished) invocations can prevent subsequent calls after the clock is
// ticked forward and make tests unreliable // ticked forward and make tests unreliable
await DataReader.getAllItems(); await flushSQLReads();
const now = Date.now(); const now = Date.now();
while (Date.now() < now + ms) { while (Date.now() < now + ms) {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await clock.tickAsync(downloadManager?.tickInterval ?? 1000); await clock.tickAsync(downloadManager?.tickInterval ?? 1000);
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await DataReader.getAllItems(); await flushSQLReads();
} }
} }