Skip to content

Commit a26b106

Browse files
authored
chore(tests): fix test speed (#468)
1 parent fe4b341 commit a26b106

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ module.exports = {
2828
setupFiles: [ './jest.setup.js' ],
2929

3030
setupFilesAfterEnv: ['./jest.setup.redis-mock.js', './jest.setup.mongo-repl-set.js'],
31+
32+
globalTeardown: './jest.global-teardown.js',
3133
};

jest.global-teardown.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const process = require('process');
2+
3+
module.exports = () => {
4+
if (process.env.CI) {
5+
setTimeout(() => {
6+
process.exit(0);
7+
}, 1000);
8+
}
9+
}

jest.setup.mongo-repl-set.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ beforeAll(async () => {
2828
* Wait for the replica set to initialize all nodes
2929
*/
3030
do {
31-
await new Promise(resolve => setTimeout(resolve, 1000));
3231
status = await admin.command({ replSetGetStatus: 1 });
3332

3433
const primary = status.members.find(member => member.stateStr === 'PRIMARY');
35-
const secondary = status.members.find(member => member.stateStr === 'SECONDARY');
3634

37-
if (primary && secondary) {
35+
if (primary) {
3836
break;
3937
}
38+
39+
await new Promise(resolve => setTimeout(resolve, 1000));
4040
} while (Date.now() - startTime < timeout);
4141

4242
console.log('✅ Replica set is stable');

workers/archiver/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DatabaseController } from '../../../lib/db/controller';
22
import { Worker } from '../../../lib/worker';
33
import * as pkg from '../package.json';
4-
import asyncForEach from '../../../lib/utils/asyncForEach';
54
import { Collection, Db, GridFSBucket, ObjectId, ObjectID } from 'mongodb';
65
import axios from 'axios';
76
import { ReleaseFileData, ReleaseRecord, ReportData, ReportDataByProject } from './types';
@@ -85,10 +84,13 @@ export default class ArchiverWorker extends Worker {
8584

8685
this.logger.info(`Start archiving at ${startDate}`);
8786

88-
const projects = await this.projectCollection.find({}).toArray();
87+
const projects = await this.projectCollection.find({}).project({
88+
_id: 1,
89+
name: 1
90+
});
8991
const projectsData: ReportDataByProject[] = [];
9092

91-
await asyncForEach(projects, async (project) => {
93+
for await (const project of projects) {
9294
const archivedEventsCount = await this.archiveProjectEvents(project);
9395

9496
const removedReleasesCount = await this.removeOldReleases(project);
@@ -98,7 +100,7 @@ export default class ArchiverWorker extends Worker {
98100
archivedEventsCount,
99101
removedReleasesCount,
100102
});
101-
});
103+
}
102104

103105
const finishDate = new Date();
104106
const dbSizeOnFinish = (await this.eventsDbConnection.stats()).dataSize;
@@ -347,9 +349,9 @@ export default class ArchiverWorker extends Worker {
347349
});
348350

349351
this.logger.info('Report notification response:', {
350-
status: response.status,
351-
statusText: response.statusText,
352-
data: response.data
352+
status: response?.status,
353+
statusText: response?.statusText,
354+
data: response?.data
353355
});
354356
}
355357

0 commit comments

Comments
 (0)