Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mongodb-memory-server to test easier locally. #11255

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"mkdirp": "0.5.5",
"mocha": "9.1.3",
"moment": "2.x",
"mongodb-memory-server": "^8.2.0",
"object-sizeof": "1.3.0",
"pug": "3.0.2",
"q": "1.5.1",
Expand All @@ -73,6 +74,7 @@
"prepublishOnly": "npm run build-browser",
"release": "git pull && git push origin master --tags && npm publish",
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
"mongo": "node ./tools/repl.js",
"test": "mocha --exit ./test/*.test.js ./test/typescript/main.test.js",
"tdd": "mocha ./test/*.test.js ./test/typescript/main.test.js --inspect --watch --recursive --watch-files ./**/*.js",
"test-cov": "nyc --reporter=html --reporter=text npm test"
Expand Down Expand Up @@ -242,6 +244,11 @@
]
}
},
"config": {
"mongodbMemoryServer": {
"disablePostinstall": true
}
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mongoose"
Expand Down
44 changes: 21 additions & 23 deletions tools/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ run().catch(error => {
});

async function run () {
const ReplSet = require('mongodb-topology-manager').ReplSet;
const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;

// Create new instance
const topology = new ReplSet('mongod', [{
// mongod process options
options: {
bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`
}
}, {
// mongod process options
options: {
bind_ip: 'localhost', port: 31001, dbpath: `/data/db/31001`
}
}, {
// Type of node
arbiterOnly: true,
// mongod process options
options: {
bind_ip: 'localhost', port: 31002, dbpath: `/data/db/31002`
}
}], {
replSet: 'rs'
const replSet = new ReplSet({
binary: {
version: process.argv[3]
},
instanceOpts: [
// Set the expiry job in MongoDB to run every second
{
port: 27017,
args: ["--setParameter", "ttlMonitorSleepSecs=1"] },
],
dbName: 'mongoose_test',
replSet: {
name: "rs0",
count: 2,
storageEngine: "wiredTiger",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing to note for the future: I typically use inMemory storage engine for tests locally, because it is much faster. I only use WT for testing transactions, etc.

But it would be great to use this script to set up MongoDB for CI so we can run a replica set and test transactions in CI.

},
});

await topology.start();

console.log('done');
await replSet.start();
await replSet.waitUntilRunning();
console.log("MongoDB-ReplicaSet is now running.")
console.log(replSet.getUri("mongoose_test"));
}