Skip to content

Commit 609a002

Browse files
fix(MongoDB): Avoid creating multiple instances of DB connection (LLC-2350) (#891)
1 parent 4f01c77 commit 609a002

File tree

12 files changed

+20
-22
lines changed

12 files changed

+20
-22
lines changed

src/apps/activities/mongoAuthRepo/tests/getClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const TEST_OAUTH_TOKEN = {
4949
};
5050

5151
describe('getClient from mongo client', () => {
52-
const connection = connectToMongoDb();
52+
const connection = connectToMongoDb;
5353
const authRepo = mongoFactory({ db: connection });
5454

5555
beforeEach(async () => {

src/apps/agents/mongoAuthRepo/tests/getClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const TEST_OAUTH_TOKEN = {
4949
};
5050

5151
describe('getClient from mongo client', () => {
52-
const connection = connectToMongoDb();
52+
const connection = connectToMongoDb;
5353
const authRepo = mongoFactory({ db: connection });
5454

5555
beforeEach(async () => {

src/apps/statements/repo/authRepo/getClient/mongo.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const TEST_OAUTH_TOKEN = {
5151
};
5252

5353
describe(__filename, () => {
54-
const connection = connectToMongoDb();
54+
const connection = connectToMongoDb;
5555
const authRepo = mongoFactory({ db: connection });
5656

5757
beforeEach(async () => {

src/apps/statements/repo/authRepo/utils/mongoAuth/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FactoryConfig from './FactoryConfig';
66

77
export default (factoryConfig?: FactoryConfig): Facade => {
88
const facadeConfig: FacadeConfig =
9-
factoryConfig !== undefined ? factoryConfig : { db: connectToMongoDb() };
9+
factoryConfig !== undefined ? factoryConfig : { db: connectToMongoDb };
1010
return {
1111
getClient: getClient(facadeConfig),
1212
};

src/apps/statements/repo/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const repoFactoryConfig: RepoFactoryConfig = {
1010
facade: config.repoFactory.authRepoName,
1111
fake: {},
1212
mongo: {
13-
db: connectToMongoDb(),
13+
db: connectToMongoDb,
1414
},
1515
},
1616
events: {
@@ -24,7 +24,7 @@ export const repoFactoryConfig: RepoFactoryConfig = {
2424
models: {
2525
facade: config.repoFactory.modelsRepoName,
2626
mongo: {
27-
db: connectToMongoDb(),
27+
db: connectToMongoDb,
2828
maxTimeMs: config.defaultTimeout,
2929
},
3030
},

src/apps/statements/repo/modelsRepo/utils/mongoModels/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default (factoryConfig?: FactoryConfig): Facade => {
2424
const facadeConfig: FacadeConfig =
2525
factoryConfig !== undefined
2626
? factoryConfig
27-
: { db: connectToMongoDb(), maxTimeMs: defaultMaxTimeMs };
27+
: { db: connectToMongoDb, maxTimeMs: defaultMaxTimeMs };
2828
return {
2929
clearRepo: async () => {
3030
await (await facadeConfig.db()).dropDatabase();
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import connectToDb from 'jscommons/dist/mongoRepo/utils/connectToDb';
22
import { once } from 'lodash';
3-
import { Db } from 'mongodb';
43
import config from '../../../../config';
54
import logger from '../../../../logger';
65

7-
export default once((): (() => Promise<Db>) => {
8-
return connectToDb({
6+
export default once(
7+
connectToDb({
98
dbName: config.mongoModelsRepo.dbName,
109
logger,
1110
url: config.mongoModelsRepo.url,
12-
});
13-
});
11+
}),
12+
);

src/apps/statements/tests/getStatements/cursorDifferentStoredValues.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('get statements with different stored value using cursor', () => {
6161
);
6262

6363
it('should return correct statements when ascending', async () => {
64-
const db = await connectToMongoDb()();
64+
const db = await connectToMongoDb();
6565
await db
6666
.collection('statements')
6767
.insertMany([statement1, statement2, statement3, statement4, statement5]);
@@ -94,7 +94,7 @@ describe('get statements with different stored value using cursor', () => {
9494
});
9595

9696
it('should return correct statements when descending cursor', async () => {
97-
const db = await connectToMongoDb()();
97+
const db = await connectToMongoDb();
9898
await db
9999
.collection('statements')
100100
.insertMany([statement1, statement2, statement3, statement4, statement5]);

src/apps/states/mongoAuthRepo/tests/getClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const TEST_OAUTH_TOKEN = {
4949
};
5050

5151
describe(__filename, () => {
52-
const connection = connectToMongoDb();
52+
const connection = connectToMongoDb;
5353
const authRepo = mongoFactory({ db: connection });
5454

5555
beforeEach(async () => {

src/conformanceServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const testClient = {
3737
};
3838

3939
(async () => {
40-
const db = await connectToMongoDb()();
40+
const db = await connectToMongoDb();
4141
console.info('Dropping database for ADL conformance tests.');
4242
await db.dropDatabase();
4343
console.info('Seeding database for ADL conformance tests.');

0 commit comments

Comments
 (0)