Skip to content

Commit

Permalink
Fix usage of uuid following dependency bump
Browse files Browse the repository at this point in the history
Issue: ARSN-465
  • Loading branch information
williamlardier committed Feb 13, 2025
1 parent 2be07f2 commit d2d14c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/storage/metadata/mongoclient/MongoClientInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as jsutil from '../../../jsutil';
import { MongoClient, Long, Db, MongoClientOptions,
ReadPreferenceMode, WithId, Collection, AnyBulkWriteOperation,
UpdateFilter, MongoServerError } from 'mongodb';
import Uuid from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import diskusage from 'diskusage';

import { generateVersionId as genVID } from '../../../versioning/VersionID';
Expand Down Expand Up @@ -2420,8 +2420,8 @@ class MongoClientInterface {
* case of concurrency. The write will fail if it already exists.
*/
getUUID(log: werelogs.Logger, cb: ArsenalCallback<string | ObjectMDStats>) {
const uuid = initialInstanceID || Uuid.v4();
this.writeUUIDIfNotExists(uuid, log, err => {
const _uuid = initialInstanceID || uuidv4();
this.writeUUIDIfNotExists(_uuid, log, err => {
if (err) {
if (err.is.InternalError) {
log.error('getUUID: error getting UUID',
Expand All @@ -2430,7 +2430,7 @@ class MongoClientInterface {
}
return this.readUUID(log, cb);
}
return cb(null, uuid);
return cb(null, _uuid);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,3 +873,37 @@ describe('MongoClientInterface, updateDeleteMaster', () => {
return done();
});
});

describe('MongoClientInterface, getUUID', () => {
it('Should return error if writeUUIDIfNotExists fails', done => {
const log = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const writeUUIDIfNotExists = mongoTestClient.writeUUIDIfNotExists;
mongoTestClient.writeUUIDIfNotExists = (uuid, log, cb) => {
return cb({ is: { InternalError: true } });
};
mongoTestClient.getUUID(log, err => {
assert(err);
mongoTestClient.writeUUIDIfNotExists = writeUUIDIfNotExists;
return done();
});
});

it('Should return uuid', done => {
const log = new werelogs.Logger('MongoClientInterface', 'debug', 'debug');
const writeUUIDIfNotExists = mongoTestClient.writeUUIDIfNotExists;
mongoTestClient.writeUUIDIfNotExists = (uuid, log, cb) => {
return cb();
};
const readUUID = mongoTestClient.readUUID;
mongoTestClient.readUUID = (log, cb) => {
return cb(null, 'uuid');
};
mongoTestClient.getUUID(log, (err, uuid) => {
assert.ifError(err);
assert.strictEqual(typeof uuid, 'string');
mongoTestClient.writeUUIDIfNotExists = writeUUIDIfNotExists;
mongoTestClient.readUUID = readUUID;
return done();
});
});
});

0 comments on commit d2d14c6

Please sign in to comment.