Skip to content

Commit

Permalink
adapt mongoQueueProcessor func test
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Nov 7, 2024
1 parent e725323 commit 78f5513
Showing 1 changed file with 6 additions and 50 deletions.
56 changes: 6 additions & 50 deletions tests/functional/ingestion/MongoQueueProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ class MongoQueueProcessorMock extends MongoQueueProcessor {
start() {
// mocks
this._mongoClient = new MongoClientMock();
this._mProducer = {
close: () => {},
publishMetrics: (metric, type, ext) => {
this.addToMetricsStore({ metric, type, ext });
},
};
this._bootstrapList = bootstrapList;
this._metricsStore = [];
}
Expand All @@ -162,30 +156,18 @@ class MongoQueueProcessorMock extends MongoQueueProcessor {
return this._consumer.sendMockEntry(entry, cb);
}

addToMetricsStore(obj) {
this._metricsStore.push(obj);
}

reset() {
this._accruedMetrics = {};
this._mongoClient.reset();
}

resetMetricsStore() {
this._metricsStore = [];
}

getAdded() {
return this._mongoClient.getAdded();
}

getDeleted() {
return this._mongoClient.getDeleted();
}

getMetricsStore() {
return this._metricsStore;
}
}

describe('MongoQueueProcessor', function mqp() {
Expand Down Expand Up @@ -282,31 +264,6 @@ describe('MongoQueueProcessor', function mqp() {
});

describe('::_processObjectQueueEntry', () => {
function validateMetricReport(type, done) {
// only 2 types of metric type reports
assert(type === 'completed' || type === 'pendingOnly');

const expectedMetricStore = [{
ext: 'ingestion',
metric: {
[LOCATION]: { ops: 1 },
},
type,
}];

const checker = setInterval(() => {
const ms = mqp.getMetricsStore();
if (ms.length !== 0) {
clearInterval(checker);
assert.deepStrictEqual(expectedMetricStore, ms);
done();
}
}, 1000);
}

afterEach(() => {
mqp.resetMetricsStore();
});

it('should save to mongo a new version entry and update fields',
done => {
Expand Down Expand Up @@ -367,7 +324,7 @@ describe('MongoQueueProcessor', function mqp() {
assert.strictEqual(repInfo.storageType, 'aws_s3');
assert.strictEqual(repInfo.dataStoreVersionId, '');

validateMetricReport('completed', done);
done();
});
});

Expand Down Expand Up @@ -432,7 +389,7 @@ describe('MongoQueueProcessor', function mqp() {
assert.strictEqual(loc.dataStoreETag, `1:${contentMD5}`);
assert.strictEqual(decode(loc.dataStoreVersionId),
NEW_VERSION_ID);
validateMetricReport('completed', done);
done();
});
});

Expand All @@ -459,7 +416,7 @@ describe('MongoQueueProcessor', function mqp() {
const added = mqp.getAdded();
assert.strictEqual(added.length, 0);

validateMetricReport('pendingOnly', done);
done();
});
});

Expand All @@ -486,7 +443,7 @@ describe('MongoQueueProcessor', function mqp() {
assert.deepStrictEqual(objVal.replicationInfo.content,
['METADATA', 'DELETE_TAGGING']);

validateMetricReport('completed', done);
done();
});
});

Expand All @@ -513,8 +470,7 @@ describe('MongoQueueProcessor', function mqp() {
assert.strictEqual(added.length, 1);
assert.deepStrictEqual(objVal.replicationInfo.content,
['METADATA', 'PUT_TAGGING']);

validateMetricReport('completed', done);
done();
});
});

Expand All @@ -541,7 +497,7 @@ describe('MongoQueueProcessor', function mqp() {
const loc = objVal.location[0];
assert.strictEqual(decode(loc.dataStoreVersionId),
nullVersionId);
validateMetricReport('completed', done);
done();
});
});
});
Expand Down

0 comments on commit 78f5513

Please sign in to comment.