Skip to content

Commit d10fbad

Browse files
committed
feat(driverBench): Implementing DriverBench
1 parent 6d23767 commit d10fbad

File tree

16 files changed

+927
-1
lines changed

16 files changed

+927
-1
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"istanbul": "^0.4.5",
2828
"jsdoc": "3.5.4",
2929
"mongodb-extended-json": "^1.10.0",
30+
"mongodb-extjson": "^2.1.0",
3031
"mongodb-mock-server": "^1.0.0",
3132
"mongodb-test-runner": "^1.1.18",
3233
"prettier": "^1.5.3",
@@ -47,7 +48,8 @@
4748
"coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/unit test/functional",
4849
"lint": "eslint lib test",
4950
"format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'",
50-
"changelog": "conventional-changelog -p angular -i HISTORY.md -s"
51+
"changelog": "conventional-changelog -p angular -i HISTORY.md -s",
52+
"bench": "node test/driverBench/"
5153
},
5254
"homepage": "https://github.com./mongodb/node-mongodb-native"
5355
}

test/driverBench/common.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const MongoClient = require('../../lib/mongo_client');
6+
const GridFsBucket = require('../../lib/gridfs-stream');
7+
8+
const DB_NAME = 'perftest';
9+
const COLLECTION_NAME = 'corpus';
10+
11+
const SPEC_DIRECTORY = path.resolve(__dirname, 'spec');
12+
13+
function loadSpecFile(filePath, encoding) {
14+
const fp = [SPEC_DIRECTORY].concat(filePath);
15+
return fs.readFileSync(path.join.apply(path, fp), encoding);
16+
}
17+
18+
function loadSpecString(filePath) {
19+
return loadSpecFile(filePath, 'utf8');
20+
}
21+
22+
function makeClient() {
23+
this.client = new MongoClient('mongodb://localhost:27017');
24+
}
25+
26+
function connectClient() {
27+
return this.client.connect();
28+
}
29+
30+
function disconnectClient() {
31+
this.client.close();
32+
}
33+
34+
function initDb() {
35+
this.db = this.client.db(DB_NAME);
36+
}
37+
38+
function dropDb() {
39+
return this.db.dropDatabase();
40+
}
41+
42+
function createCollection() {
43+
return this.db.createCollection(COLLECTION_NAME);
44+
}
45+
46+
function initCollection() {
47+
this.collection = this.db.collection(COLLECTION_NAME);
48+
}
49+
50+
function dropCollection() {
51+
return this.collection.drop();
52+
}
53+
54+
function initBucket() {
55+
this.bucket = new GridFsBucket(this.db);
56+
}
57+
58+
function dropBucket() {
59+
return this.bucket && this.bucket.drop();
60+
}
61+
62+
function makeLoadJSON(name) {
63+
return function() {
64+
this.doc = JSON.parse(loadSpecString(['single_and_multi_document', name]));
65+
};
66+
}
67+
68+
module.exports = {
69+
makeClient,
70+
connectClient,
71+
disconnectClient,
72+
initDb,
73+
dropDb,
74+
createCollection,
75+
initCollection,
76+
dropCollection,
77+
makeLoadJSON,
78+
loadSpecFile,
79+
loadSpecString,
80+
initBucket,
81+
dropBucket
82+
};

0 commit comments

Comments
 (0)