Skip to content

Commit

Permalink
feat(driverBench): Implementing DriverBench
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian committed Mar 29, 2018
1 parent 6d23767 commit d10fbad
Show file tree
Hide file tree
Showing 16 changed files with 927 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -27,6 +27,7 @@
"istanbul": "^0.4.5",
"jsdoc": "3.5.4",
"mongodb-extended-json": "^1.10.0",
"mongodb-extjson": "^2.1.0",
"mongodb-mock-server": "^1.0.0",
"mongodb-test-runner": "^1.1.18",
"prettier": "^1.5.3",
Expand All @@ -47,7 +48,8 @@
"coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/unit test/functional",
"lint": "eslint lib test",
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
"changelog": "conventional-changelog -p angular -i HISTORY.md -s"
"changelog": "conventional-changelog -p angular -i HISTORY.md -s",
"bench": "node test/driverBench/"
},
"homepage": "https://github.com/mongodb/node-mongodb-native"
}
82 changes: 82 additions & 0 deletions test/driverBench/common.js
@@ -0,0 +1,82 @@
'use strict';

const fs = require('fs');
const path = require('path');
const MongoClient = require('../../lib/mongo_client');
const GridFsBucket = require('../../lib/gridfs-stream');

const DB_NAME = 'perftest';
const COLLECTION_NAME = 'corpus';

const SPEC_DIRECTORY = path.resolve(__dirname, 'spec');

function loadSpecFile(filePath, encoding) {
const fp = [SPEC_DIRECTORY].concat(filePath);
return fs.readFileSync(path.join.apply(path, fp), encoding);
}

function loadSpecString(filePath) {
return loadSpecFile(filePath, 'utf8');
}

function makeClient() {
this.client = new MongoClient('mongodb://localhost:27017');
}

function connectClient() {
return this.client.connect();
}

function disconnectClient() {
this.client.close();
}

function initDb() {
this.db = this.client.db(DB_NAME);
}

function dropDb() {
return this.db.dropDatabase();
}

function createCollection() {
return this.db.createCollection(COLLECTION_NAME);
}

function initCollection() {
this.collection = this.db.collection(COLLECTION_NAME);
}

function dropCollection() {
return this.collection.drop();
}

function initBucket() {
this.bucket = new GridFsBucket(this.db);
}

function dropBucket() {
return this.bucket && this.bucket.drop();
}

function makeLoadJSON(name) {
return function() {
this.doc = JSON.parse(loadSpecString(['single_and_multi_document', name]));
};
}

module.exports = {
makeClient,
connectClient,
disconnectClient,
initDb,
dropDb,
createCollection,
initCollection,
dropCollection,
makeLoadJSON,
loadSpecFile,
loadSpecString,
initBucket,
dropBucket
};

0 comments on commit d10fbad

Please sign in to comment.