From 904a11f542cad87eb5889e4cbfb614a532434676 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 11 Aug 2022 16:56:23 +0200 Subject: [PATCH 01/17] test: add basic MMS usage to mocha --- .mocharc.yml | 2 + test/common.js | 100 ++++++++++++++++++++++------------------- test/index.test.js | 8 ++-- test/mocha-fixtures.js | 47 +++++++++++++++++++ 4 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 test/mocha-fixtures.js diff --git a/.mocharc.yml b/.mocharc.yml index 1810d04bb59..efa9bf8a87b 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,2 +1,4 @@ reporter: spec # better to identify failing / slow tests than "dot" ui: bdd # explicitly setting, even though it is mocha default +require: + - test/mocha-fixtures.js diff --git a/test/common.js b/test/common.js index e0aa3b7a1bd..b65ae68bc2a 100644 --- a/test/common.js +++ b/test/common.js @@ -114,7 +114,8 @@ module.exports = function(options) { return conn; }; -function getUri(env, default_uri, db) { +function getUri(default_uri, db) { + const env = process.env.START_REPLICA_SET ? process.env.MONGOOSE_REPLSET_URI : process.env.MONGOOSE_TEST_URI; const use = env ? env : default_uri; const lastIndex = use.lastIndexOf('/'); // use length if lastIndex is 9 or lower, because that would mean it found the last character of "mongodb://" @@ -134,13 +135,18 @@ const databases = module.exports.databases = [ * testing uri */ -module.exports.uri = getUri(process.env.MONGOOSE_TEST_URI, 'mongodb://127.0.0.1:27017/', databases[0]); +// the following has to be done, otherwise mocha will evaluate this before running the global-setup, where it becomes the default +Object.defineProperty(module.exports, 'uri', { + get: () => getUri('mongodb://127.0.0.1:27017/', databases[0]) +}); /** * testing uri for 2nd db */ -module.exports.uri2 = getUri(process.env.MONGOOSE_TEST_URI, 'mongodb://127.0.0.1:27017/', databases[1]); +Object.defineProperty(module.exports, 'uri2', { + get: () => getUri('mongodb://127.0.0.1:27017/', databases[1]) +}); /** * expose mongoose @@ -177,27 +183,29 @@ module.exports.mongodVersion = async function() { }; async function dropDBs() { + this.timeout(60000); + const db = await module.exports({ noErrorListener: true }).asPromise(); await db.dropDatabase(); await db.close(); } -before(async function() { - this.timeout(60000); - if (process.env.START_REPLICA_SET) { - const uri = await startReplicaSet(); +// before(async function() { +// this.timeout(60000); +// if (process.env.START_REPLICA_SET) { +// const uri = await startReplicaSet(); - module.exports.uri = uri; - module.exports.uri2 = uri.replace(databases[0], databases[1]); +// module.exports.uri = uri; +// module.exports.uri2 = uri.replace(databases[0], databases[1]); - process.env.REPLICA_SET = 'rs0'; +// process.env.REPLICA_SET = 'rs0'; - const conn = mongoose.createConnection(uri); - await conn.asPromise(); - await conn.db.collection('test').findOne(); - await conn.close(); - } -}); +// const conn = mongoose.createConnection(uri); +// await conn.asPromise(); +// await conn.db.collection('test').findOne(); +// await conn.close(); +// } +// }); before(dropDBs); @@ -224,33 +232,33 @@ process.on('unhandledRejection', function(error, promise) { throw error; }); -async function startReplicaSet() { - const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet; - - // Create new instance - const replSet = new ReplSet({ - binary: { - version: '5.0.4' - }, - instanceOpts: [ - // Set the expiry job in MongoDB to run every second - { - port: 27017, - args: ['--setParameter', 'ttlMonitorSleepSecs=1'] - } - ], - dbName: databases[0], - replSet: { - name: 'rs0', - count: 2, - storageEngine: 'wiredTiger' - } - }); - - await replSet.start(); - await replSet.waitUntilRunning(); - - await new Promise(resolve => setTimeout(resolve, 10000)); - - return replSet.getUri(databases[0]); -} +// async function startReplicaSet() { +// const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet; + +// // Create new instance +// const replSet = new ReplSet({ +// binary: { +// version: '5.0.4' +// }, +// instanceOpts: [ +// // Set the expiry job in MongoDB to run every second +// { +// port: 27017, +// args: ['--setParameter', 'ttlMonitorSleepSecs=1'] +// } +// ], +// dbName: databases[0], +// replSet: { +// name: 'rs0', +// count: 2, +// storageEngine: 'wiredTiger' +// } +// }); + +// await replSet.start(); +// await replSet.waitUntilRunning(); + +// await new Promise(resolve => setTimeout(resolve, 10000)); + +// return replSet.getUri(databases[0]); +// } diff --git a/test/index.test.js b/test/index.test.js index b67aee31763..14c3529c6f9 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -717,13 +717,13 @@ describe('mongoose module:', function() { it('with replica set', async function() { const mong = new Mongoose(); - const uri = process.env.MONGOOSE_SET_TEST_URI; + // const start.uri = process.env.MONGOOSE_SET_TEST_URI; - if (!uri) { - return; + if (!start.uri) { + return this.skip(); } - await mong.connect(uri, options); + await mong.connect(start.uri, options); await mong.connection.close(); }); diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js new file mode 100644 index 00000000000..b3d183e00bb --- /dev/null +++ b/test/mocha-fixtures.js @@ -0,0 +1,47 @@ +'use strict'; + +const mms = require('mongodb-memory-server'); +const mmsresolve = require('mongodb-memory-server-core/lib/util/resolveConfig'); + +/* + * Default MMS mongodb version is used, unless MONGOMS_VERSION is set (which is set with the matrix in test.yml for CI) + */ + +// a single-instance running for single-instance tests +let mongoinstance; + +// a replset-instance for running repl-set tests +let mongorreplset; + +// decide wheter to start a in-memory or not +const startMemory = !mmsresolve.envToBool(process.env.CI) && !process.env.MONGOOSE_TEST_URI; + +module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { + let instanceuri; + let replseturi; + if (startMemory) { // Config to decided if an mongodb-memory-server instance should be used + // it's needed in global space, because we don't want to create a new instance every test-suite + mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); + const uri = mongoinstance.getUri(); + instanceuri = uri.slice(0, uri.lastIndexOf('/')); + + mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: '3', args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); // using 3 because even numbers can lead to vote problems + replseturi = mongorreplset.getUri(); + } else { + instanceuri = process.env.MONGOOSE_TEST_URI; + replseturi = ''; + } + + process.env.MONGOOSE_TEST_URI = instanceuri; + process.env.MONGOOSE_REPLSET_URI = replseturi; + + // The following is to make sure the database is clean before an test starts + // const client = new mongodb.MongoClient(finaluri); + // await client.connect(); +}; + +module.exports.mochaGlobalTeardown = async function mochaGlobalTeardown() { + if (mongoinstance) { // Config to decided if an mongodb-memory-server instance should be used + await mongoinstance.stop(); + } +}; From 098da1331c3e347a055a74aefb223a8abfc48be2 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 11 Aug 2022 17:04:58 +0200 Subject: [PATCH 02/17] chore(test.yml): update for using MMS in tests --- .github/workflows/test.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8edfff05c8c..9b1713f0759 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,6 +59,8 @@ jobs: - os: ubuntu-20.04 # exclude because there are no <4.4 mongodb builds for 2004 mongodb: 4.0.2 name: Node ${{ matrix.node }} MongoDB ${{ matrix.mongodb }} OS ${{ matrix.os }} + env: + MONGOMS_VERSION: ${{ matrix.mongodb }} steps: - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 @@ -69,16 +71,16 @@ jobs: - run: npm install - - name: Setup - run: | - wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz - tar xf mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz - mkdir -p ./data/db/27017 ./data/db/27000 - printf "\ntimeout: 8000" >> ./.mocharc.yml - ./mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017 - sleep 2 - mongod --version - echo `pwd`/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin >> $GITHUB_PATH + # - name: Setup + # run: | + # wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz + # tar xf mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz + # mkdir -p ./data/db/27017 ./data/db/27000 + # printf "\ntimeout: 8000" >> ./.mocharc.yml + # ./mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017 + # sleep 2 + # mongod --version + # echo `pwd`/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin >> $GITHUB_PATH - name: NPM Test without Coverage run: npm test if: matrix.coverage != true From 47c6b23e79df93ae2b916120d085ea2655fcfd47 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 13 Aug 2022 14:17:26 +0200 Subject: [PATCH 03/17] chore(mocha-fixtures): update deciding wheter to start a memory instance or not also stops the replset on teardown now --- test/mocha-fixtures.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index b3d183e00bb..906cc1342c0 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -1,7 +1,6 @@ 'use strict'; const mms = require('mongodb-memory-server'); -const mmsresolve = require('mongodb-memory-server-core/lib/util/resolveConfig'); /* * Default MMS mongodb version is used, unless MONGOMS_VERSION is set (which is set with the matrix in test.yml for CI) @@ -14,21 +13,25 @@ let mongoinstance; let mongorreplset; // decide wheter to start a in-memory or not -const startMemory = !mmsresolve.envToBool(process.env.CI) && !process.env.MONGOOSE_TEST_URI; +const startMemoryInstance = !process.env.MONGOOSE_TEST_URI; +const startMemoryReplset = !process.env.MONGOOSE_REPLSET_URI; module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { let instanceuri; let replseturi; - if (startMemory) { // Config to decided if an mongodb-memory-server instance should be used + if (startMemoryInstance) { // Config to decided if an mongodb-memory-server instance should be used // it's needed in global space, because we don't want to create a new instance every test-suite mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); const uri = mongoinstance.getUri(); instanceuri = uri.slice(0, uri.lastIndexOf('/')); + } else { + instanceuri = process.env.MONGOOSE_TEST_URI; + } + if (startMemoryReplset) { mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: '3', args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); // using 3 because even numbers can lead to vote problems replseturi = mongorreplset.getUri(); } else { - instanceuri = process.env.MONGOOSE_TEST_URI; replseturi = ''; } @@ -44,4 +47,7 @@ module.exports.mochaGlobalTeardown = async function mochaGlobalTeardown() { if (mongoinstance) { // Config to decided if an mongodb-memory-server instance should be used await mongoinstance.stop(); } + if (mongorreplset) { + await mongorreplset.stop(); + } }; From af1ea90db420d5d1634486a65300774a7f367419 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:29:00 +0200 Subject: [PATCH 04/17] chore(test.yml): update used mongodb versions --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b1713f0759..8d257383efe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,14 +41,14 @@ jobs: matrix: node: [12, 14, 16, 18] os: [ubuntu-18.04, ubuntu-20.04] - mongodb: [4.0.2, 5.0.2, 6.0.0] + mongodb: [4.0.28, 5.0.8, 6.0.0] include: - os: ubuntu-18.04 mongodb-os: ubuntu1804 - os: ubuntu-20.04 mongodb-os: ubuntu2004 - os: ubuntu-20.04 # customize on which matrix the coverage will be collected on - mongodb: 5.0.2 + mongodb: 5.0.11 node: 16 coverage: true exclude: From d6945a592e4dca7fe4ed74a52f833f7e0a24edc7 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:34:22 +0200 Subject: [PATCH 05/17] chore(package.json): update mongodb-memory-server to 8.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e322c3a6ab..2b9e52cb7c1 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mkdirp": "^1.0.4", "mocha": "10.0.0", "moment": "2.x", - "mongodb-memory-server": "8.8.0", + "mongodb-memory-server": "8.9.1", "ncp": "^2.0.0", "nyc": "15.1.0", "pug": "3.0.2", From 47b196e5b3c14e8e3676f9b42e5fee8054c5b17a Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:38:11 +0200 Subject: [PATCH 06/17] chore(test.yml): comment-out includes for unused "mongodb-os" --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d257383efe..733f5a81a19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,10 +43,10 @@ jobs: os: [ubuntu-18.04, ubuntu-20.04] mongodb: [4.0.28, 5.0.8, 6.0.0] include: - - os: ubuntu-18.04 - mongodb-os: ubuntu1804 - - os: ubuntu-20.04 - mongodb-os: ubuntu2004 + # - os: ubuntu-18.04 + # mongodb-os: ubuntu1804 + # - os: ubuntu-20.04 + # mongodb-os: ubuntu2004 - os: ubuntu-20.04 # customize on which matrix the coverage will be collected on mongodb: 5.0.11 node: 16 From a910b8be8a2a8e100be0020f2c98cf6be7b007ae Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:39:36 +0200 Subject: [PATCH 07/17] test(mocha-fixtures): change string number to actual number --- test/mocha-fixtures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index 906cc1342c0..15fa0f3602e 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -29,7 +29,7 @@ module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { } if (startMemoryReplset) { - mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: '3', args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); // using 3 because even numbers can lead to vote problems + mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: 3, args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); // using 3 because even numbers can lead to vote problems replseturi = mongorreplset.getUri(); } else { replseturi = ''; From 9aabf6256714b095a1daf7e5ed6460afd5c587dd Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:49:33 +0200 Subject: [PATCH 08/17] test(mocha-fixtures): set some MMS environment options depending on context --- .github/workflows/test.yml | 1 + test/mocha-fixtures.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 733f5a81a19..6edf8c3864b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,7 @@ jobs: name: Node ${{ matrix.node }} MongoDB ${{ matrix.mongodb }} OS ${{ matrix.os }} env: MONGOMS_VERSION: ${{ matrix.mongodb }} + MONGOMS_PREFER_GLOBAL_PATH: 1 steps: - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index 15fa0f3602e..a573d99f51c 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -19,6 +19,14 @@ const startMemoryReplset = !process.env.MONGOOSE_REPLSET_URI; module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { let instanceuri; let replseturi; + + process.env.RUNTIME_DOWNLOAD = '1'; // ensure MMS is able to download binaries in this context + + // set some options when running in a CI + if (process.env.CI) { + process.env.MONGOMS_PREFER_GLOBAL_PATH = '1'; // set MMS to use "~/.cache/mongodb-binaries" even when the path does not yet exist + } + if (startMemoryInstance) { // Config to decided if an mongodb-memory-server instance should be used // it's needed in global space, because we don't want to create a new instance every test-suite mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); From 518ee0e46ee655880b031f2e8fa5e3fc5427a27c Mon Sep 17 00:00:00 2001 From: hasezoey Date: Thu, 1 Sep 2022 10:50:35 +0200 Subject: [PATCH 09/17] chore(test.yml): cache global mongodb-binaries --- .github/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6edf8c3864b..205d36611d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,13 @@ jobs: with: node-version: ${{ matrix.node }} + - name: Load MongoDB binary cache + id: cache-mongodb-binaries + uses: actions/cache@v3 + with: + path: ~/.cache/mongodb-binaries + key: ${{ matrix.os }}-${{ matrix.mongodb }} + - run: npm install # - name: Setup From efaf89b2be02f540c54dac1795b2fcb595a21999 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 12 Sep 2022 09:30:21 +0200 Subject: [PATCH 10/17] chore(mocha-fixtures): dont remove everything after last "/" for single mongo instance --- test/mocha-fixtures.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index a573d99f51c..ec1db1f3bbe 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -30,8 +30,7 @@ module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { if (startMemoryInstance) { // Config to decided if an mongodb-memory-server instance should be used // it's needed in global space, because we don't want to create a new instance every test-suite mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); - const uri = mongoinstance.getUri(); - instanceuri = uri.slice(0, uri.lastIndexOf('/')); + instanceuri = mongoinstance.getUri(); } else { instanceuri = process.env.MONGOOSE_TEST_URI; } From 48973effae9ccea2f62bfe2c7bde3e1fe52620ad Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 12 Sep 2022 09:36:48 +0200 Subject: [PATCH 11/17] text(common): update "getUri" to not ignore URI query-parameters --- test/common.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index b65ae68bc2a..d3feb2389e5 100644 --- a/test/common.js +++ b/test/common.js @@ -118,8 +118,11 @@ function getUri(default_uri, db) { const env = process.env.START_REPLICA_SET ? process.env.MONGOOSE_REPLSET_URI : process.env.MONGOOSE_TEST_URI; const use = env ? env : default_uri; const lastIndex = use.lastIndexOf('/'); + const dbQueryString = use.slice(lastIndex); + const queryIndex = dbQueryString.indexOf('?'); + const query = queryIndex === -1 ? '' : '?' + dbQueryString.slice(queryIndex + 1); // use length if lastIndex is 9 or lower, because that would mean it found the last character of "mongodb://" - return use.slice(0, lastIndex <= 9 ? use.length : lastIndex) + `/${db}`; + return use.slice(0, lastIndex <= 9 ? use.length : lastIndex) + `/${db}` + query; } /** From bdedd70b5ed7b1e94e5f31678e3b43ed434f235c Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 09:57:03 +0200 Subject: [PATCH 12/17] test: change MMS to use "storageEngine: 'wiredTiger'" --- test/mocha-fixtures.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index ec1db1f3bbe..82bc76080e2 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -29,14 +29,14 @@ module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { if (startMemoryInstance) { // Config to decided if an mongodb-memory-server instance should be used // it's needed in global space, because we don't want to create a new instance every test-suite - mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); + mongoinstance = await mms.MongoMemoryServer.create({ instance: { args: ['--setParameter', 'ttlMonitorSleepSecs=1'], storageEngine: 'wiredTiger' } }); instanceuri = mongoinstance.getUri(); } else { instanceuri = process.env.MONGOOSE_TEST_URI; } if (startMemoryReplset) { - mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: 3, args: ['--setParameter', 'ttlMonitorSleepSecs=1'] } }); // using 3 because even numbers can lead to vote problems + mongorreplset = await mms.MongoMemoryReplSet.create({ replSet: { count: 3, args: ['--setParameter', 'ttlMonitorSleepSecs=1'], storageEngine: 'wiredTiger' } }); // using 3 because even numbers can lead to vote problems replseturi = mongorreplset.getUri(); } else { replseturi = ''; From dec18fe2af4f2d7e52dded193c32a600c4bd2e47 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 10:04:37 +0200 Subject: [PATCH 13/17] style: remove commented-out MMS code --- .github/workflows/test.yml | 11 --------- test/common.js | 48 -------------------------------------- test/mocha-fixtures.js | 4 ---- 3 files changed, 63 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 205d36611d5..baa2aca1cde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,17 +78,6 @@ jobs: key: ${{ matrix.os }}-${{ matrix.mongodb }} - run: npm install - - # - name: Setup - # run: | - # wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz - # tar xf mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}.tgz - # mkdir -p ./data/db/27017 ./data/db/27000 - # printf "\ntimeout: 8000" >> ./.mocharc.yml - # ./mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017 - # sleep 2 - # mongod --version - # echo `pwd`/mongodb-linux-x86_64-${{ matrix.mongodb-os }}-${{ matrix.mongodb }}/bin >> $GITHUB_PATH - name: NPM Test without Coverage run: npm test if: matrix.coverage != true diff --git a/test/common.js b/test/common.js index d60a9e28604..6e036983c91 100644 --- a/test/common.js +++ b/test/common.js @@ -193,23 +193,6 @@ async function dropDBs() { await db.close(); } -// before(async function() { -// this.timeout(60000); -// if (process.env.START_REPLICA_SET) { -// const uri = await startReplicaSet(); - -// module.exports.uri = uri; -// module.exports.uri2 = uri.replace(databases[0], databases[1]); - -// process.env.REPLICA_SET = 'rs0'; - -// const conn = mongoose.createConnection(uri); -// await conn.asPromise(); -// await conn.db.collection('test').findOne(); -// await conn.close(); -// } -// }); - before(dropDBs); after(dropDBs); @@ -223,34 +206,3 @@ process.on('unhandledRejection', function(error, promise) { } throw error; }); - -// async function startReplicaSet() { -// const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet; - -// // Create new instance -// const replSet = new ReplSet({ -// binary: { -// version: '5.0.4' -// }, -// instanceOpts: [ -// // Set the expiry job in MongoDB to run every second -// { -// port: 27017, -// args: ['--setParameter', 'ttlMonitorSleepSecs=1'] -// } -// ], -// dbName: databases[0], -// replSet: { -// name: 'rs0', -// count: 2, -// storageEngine: 'wiredTiger' -// } -// }); - -// await replSet.start(); -// await replSet.waitUntilRunning(); - -// await new Promise(resolve => setTimeout(resolve, 10000)); - -// return replSet.getUri(databases[0]); -// } diff --git a/test/mocha-fixtures.js b/test/mocha-fixtures.js index 82bc76080e2..2e537071c52 100644 --- a/test/mocha-fixtures.js +++ b/test/mocha-fixtures.js @@ -44,10 +44,6 @@ module.exports.mochaGlobalSetup = async function mochaGlobalSetup() { process.env.MONGOOSE_TEST_URI = instanceuri; process.env.MONGOOSE_REPLSET_URI = replseturi; - - // The following is to make sure the database is clean before an test starts - // const client = new mongodb.MongoClient(finaluri); - // await client.connect(); }; module.exports.mochaGlobalTeardown = async function mochaGlobalTeardown() { From cbc8233a7add3494d548cae11074ebb43fe86c5d Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 10:06:03 +0200 Subject: [PATCH 14/17] chore(package.json): update mongodb-memory-server to 8.9.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a2fc5d5a64..9fb2694ef1e 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mkdirp": "^1.0.4", "mocha": "10.0.0", "moment": "2.x", - "mongodb-memory-server": "8.9.1", + "mongodb-memory-server": "8.9.2", "ncp": "^2.0.0", "nyc": "15.1.0", "pug": "3.0.2", From ba5ff0fb1128e1af18caac40ab2c8cd4d4b8f05f Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 11:39:31 +0200 Subject: [PATCH 15/17] chore(package.json): update mongodb-memory-server to 8.9.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fb2694ef1e..55701e9f481 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mkdirp": "^1.0.4", "mocha": "10.0.0", "moment": "2.x", - "mongodb-memory-server": "8.9.2", + "mongodb-memory-server": "8.9.3", "ncp": "^2.0.0", "nyc": "15.1.0", "pug": "3.0.2", From 1412b20898ebe5589b58b49ce92d7747461a1edf Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 12:00:38 +0200 Subject: [PATCH 16/17] style(index.test): remove commented-out code from MMS --- test/index.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 14c3529c6f9..49ae3c65242 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -717,7 +717,6 @@ describe('mongoose module:', function() { it('with replica set', async function() { const mong = new Mongoose(); - // const start.uri = process.env.MONGOOSE_SET_TEST_URI; if (!start.uri) { return this.skip(); From e0ac444144e6617d715b10f6b6885ca9ff0bb336 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sun, 25 Sep 2022 12:01:18 +0200 Subject: [PATCH 17/17] chore(workflows/test): remove commented-out "include" array values --- .github/workflows/test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index baa2aca1cde..6d68b4400d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,10 +43,6 @@ jobs: os: [ubuntu-18.04, ubuntu-20.04] mongodb: [4.0.28, 5.0.8, 6.0.0] include: - # - os: ubuntu-18.04 - # mongodb-os: ubuntu1804 - # - os: ubuntu-20.04 - # mongodb-os: ubuntu2004 - os: ubuntu-20.04 # customize on which matrix the coverage will be collected on mongodb: 5.0.11 node: 16