diff --git a/services/web/app/src/infrastructure/Mongoose.js b/services/web/app/src/infrastructure/Mongoose.js index 6276c0f597..528d72fd99 100644 --- a/services/web/app/src/infrastructure/Mongoose.js +++ b/services/web/app/src/infrastructure/Mongoose.js @@ -2,7 +2,6 @@ const mongoose = require('mongoose') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') const { addConnectionDrainer } = require('./GracefulShutdown') -const { collectStatsForDb } = require('./mongodb') if ( typeof global.beforeEach === 'function' && @@ -61,8 +60,6 @@ async function getNativeDb() { return mongooseInstance.connection.db } -getNativeDb().then(db => collectStatsForDb(db, 'mongoose')) - mongoose.getNativeDb = getNativeDb mongoose.connectionPromise = connectionPromise diff --git a/services/web/app/src/infrastructure/mongodb.js b/services/web/app/src/infrastructure/mongodb.js index 707cc35c72..9d27f96b2b 100644 --- a/services/web/app/src/infrastructure/mongodb.js +++ b/services/web/app/src/infrastructure/mongodb.js @@ -1,11 +1,10 @@ const Metrics = require('@overleaf/metrics') -const Settings = require('@overleaf/settings') -const { MongoClient, ObjectId } = require('mongodb') +const { ObjectId } = require('mongodb') const OError = require('@overleaf/o-error') const { - addConnectionDrainer, addOptionalCleanupHandlerAfterDrainingConnections, } = require('./GracefulShutdown') +const { getNativeDb } = require('./Mongoose') if ( typeof global.beforeEach === 'function' && @@ -16,15 +15,6 @@ if ( ) } -const clientPromise = MongoClient.connect( - Settings.mongo.url, - Settings.mongo.options -) -addConnectionDrainer('mongodb', async () => { - const client = await clientPromise - client.close() -}) - let setupDbPromise async function waitForDb() { if (!setupDbPromise) { @@ -35,8 +25,8 @@ async function waitForDb() { const db = {} async function setupDb() { - const internalDb = (await clientPromise).db() - collectStatsForDb(internalDb, 'native') + const internalDb = await getNativeDb() + collectStatsForDb(internalDb, 'shared') db.contacts = internalDb.collection('contacts') db.deletedFiles = internalDb.collection('deletedFiles') @@ -92,14 +82,14 @@ async function setupDb() { } async function getCollectionNames() { - const internalDb = (await clientPromise).db() + const internalDb = await getNativeDb() const collections = await internalDb.collections() return collections.map(collection => collection.collectionName) } async function dropTestDatabase() { - const internalDb = (await clientPromise).db() + const internalDb = await getNativeDb() const dbName = internalDb.databaseName const env = process.env.NODE_ENV @@ -116,7 +106,7 @@ async function dropTestDatabase() { * WARNING: Consider using a pre-populated collection from `db` to avoid typos! */ async function getCollectionInternal(name) { - const internalDb = (await clientPromise).db() + const internalDb = await getNativeDb() return internalDb.collection(name) } diff --git a/services/web/test/acceptance/src/helpers/settings.js b/services/web/test/acceptance/src/helpers/settings.js index 2070bbfac1..005f953133 100644 --- a/services/web/test/acceptance/src/helpers/settings.js +++ b/services/web/test/acceptance/src/helpers/settings.js @@ -2,7 +2,8 @@ function filterOutput(line) { return ( !line.startsWith('Using settings from ') && !line.startsWith('Using default settings from ') && - !line.startsWith('CoffeeScript settings file') + !line.startsWith('CoffeeScript settings file') && + !line.includes('mongoose default connection open') ) }