Skip to content

Commit

Permalink
Merge branch 'master' into separate-test-lint-config
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Nov 8, 2023
2 parents a83d622 + 24e6400 commit 5ae99dd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
6 changes: 3 additions & 3 deletions tests/performance/perf.attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function (PouchDB, callback) {
name: 'basic-attachments',
assertions: 1,
iterations: 1000,
setup: function (db, callback) {
setup: function (db, _, callback) {

var blob = randomBlob(50000);
db._blob = blob;
Expand All @@ -56,7 +56,7 @@ module.exports = function (PouchDB, callback) {
name: 'many-attachments-base64',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
const doc = {
_id: 'doc1',
_attachments: {},
Expand All @@ -77,7 +77,7 @@ module.exports = function (PouchDB, callback) {
name: 'many-attachments-binary',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
const doc = {
_id: 'doc1',
_attachments: {},
Expand Down
26 changes: 13 additions & 13 deletions tests/performance/perf.basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (PouchDB, callback) {
name: 'basic-inserts',
assertions: 1,
iterations: 1000,
setup: function (db, callback) {
setup: function (db, _, callback) {
callback(null, {'yo': 'dawg'});
},
test: function (db, itr, doc, done) {
Expand All @@ -25,7 +25,7 @@ module.exports = function (PouchDB, callback) {
name: 'bulk-inserts',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 100; i++) {
docs.push({much : 'docs', very : 'bulk'});
Expand All @@ -40,7 +40,7 @@ module.exports = function (PouchDB, callback) {
name: 'bulk-inserts-large-docs',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];

for (var d = 0; d < 100; d++) {
Expand All @@ -61,7 +61,7 @@ module.exports = function (PouchDB, callback) {
name: 'bulk-inserts-massive-docs',
assertions: 1,
iterations: 10,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];

// Depth is an important factor here. Depth makes any kind of recursive
Expand Down Expand Up @@ -102,7 +102,7 @@ module.exports = function (PouchDB, callback) {
name: 'basic-updates',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 100; i++) {
docs.push({});
Expand All @@ -123,9 +123,9 @@ module.exports = function (PouchDB, callback) {
name: 'basic-gets',
assertions: 1,
iterations: 1000,
setup: function (db, callback) {
setup: function (db, { iterations }, callback) {
var docs = [];
for (var i = 0; i < this.iterations; i++) {
for (var i = 0; i < iterations; i++) {
docs.push({_id : commonUtils.createDocId(i),
foo : 'bar', baz : 'quux'});
}
Expand All @@ -139,7 +139,7 @@ module.exports = function (PouchDB, callback) {
name: 'all-docs-skip-limit',
assertions: 1,
iterations: 10,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 1000; i++) {
docs.push({_id : commonUtils.createDocId(i),
Expand All @@ -166,7 +166,7 @@ module.exports = function (PouchDB, callback) {
name: 'all-docs-startkey-endkey',
assertions: 1,
iterations: 10,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 1000; i++) {
docs.push({
Expand Down Expand Up @@ -199,7 +199,7 @@ module.exports = function (PouchDB, callback) {
name: 'all-docs-keys',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 1000; i++) {
docs.push({_id : commonUtils.createDocId(i),
Expand All @@ -226,7 +226,7 @@ module.exports = function (PouchDB, callback) {
name: 'all-docs-include-docs',
assertions: 1,
iterations: 100,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 1000; i++) {
docs.push({
Expand All @@ -253,7 +253,7 @@ module.exports = function (PouchDB, callback) {
name: 'pull-replication-perf-skimdb',
assertions: 1,
iterations: 0,
setup: function (localDB, callback) {
setup: function (localDB, { iterations }, callback) {
// The NPM registry is a couchdb database. "skimdb" is the NPM
// registry, minus the actual packages, found at
// https://skimdb.npmjs.com/registry, and an example of a real, public
Expand All @@ -266,7 +266,7 @@ module.exports = function (PouchDB, callback) {
});
var localPouches = [];

for (var i = 0; i < this.iterations; ++i) {
for (var i = 0; i < iterations; ++i) {
localPouches[i] = new PouchDB(commonUtils.safeRandomDBName());
}

Expand Down
12 changes: 6 additions & 6 deletions tests/performance/perf.find.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (PouchDB, callback) {
name: 'create-index',
assertions: 1,
iterations: 1,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
callback();
Expand All @@ -42,7 +42,7 @@ module.exports = function (PouchDB, callback) {
name: 'simple-find-query',
assertions: 1,
iterations: 5,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
return db.createIndex({
Expand All @@ -66,7 +66,7 @@ module.exports = function (PouchDB, callback) {
name: 'simple-find-query-no-index',
assertions: 1,
iterations: 5,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
callback();
Expand All @@ -84,7 +84,7 @@ module.exports = function (PouchDB, callback) {
name: 'complex-find-query',
assertions: 1,
iterations: 5,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
return db.createIndex({
Expand Down Expand Up @@ -113,7 +113,7 @@ module.exports = function (PouchDB, callback) {
name: 'complex-find-query-no-index',
assertions: 1,
iterations: 5,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
callback();
Expand All @@ -136,7 +136,7 @@ module.exports = function (PouchDB, callback) {
name: 'multi-field-query',
assertions: 1,
iterations: 5,
setup: function (db, callback) {
setup: function (db, _, callback) {
db.bulkDocs(makeTestDocs())
.then(function () {
return db.createIndex({
Expand Down
8 changes: 4 additions & 4 deletions tests/performance/perf.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (PouchDB, callback) {
name: 'temp-views',
assertions: 1,
iterations: 1,
setup: function (db, callback) {
setup: function (db, _, callback) {
var tasks = [];
for (var i = 0; i < 100; i++) {
tasks.push(i);
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = function (PouchDB, callback) {
name: 'build-secondary-index',
assertions: 1,
iterations: 1,
setup: function (db, callback) {
setup: function (db, _, callback) {
var docs = [];
for (var i = 0; i < 1000; i++) {
docs.push({});
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = function (PouchDB, callback) {
name: 'persisted-views',
assertions: 1,
iterations: 10,
setup: function (db, callback) {
setup: function (db, _, callback) {
var tasks = [];
for (var i = 0; i < 100; i++) {
tasks.push(i);
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = function (PouchDB, callback) {
name: 'persisted-views-stale-ok',
assertions: 1,
iterations: 10,
setup: function (db, callback) {
setup: function (db, _, callback) {
var tasks = [];
for (var i = 0; i < 100; i++) {
tasks.push(i);
Expand Down
2 changes: 1 addition & 1 deletion tests/performance/replication-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function (PouchDB, Promise) {

PullRequestTestObject.prototype.setup = function (itr, gens) {
var self = this;
return function (localDB, callback) {
return function (localDB, _, callback) {
var remoteDBOpts = {ajax: {pool: {maxSockets: MAX_SOCKETS}}};
var remoteCouchUrl = commonUtils.couchHost() + "/" +
commonUtils.safeRandomDBName();
Expand Down
31 changes: 15 additions & 16 deletions tests/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ var commonUtils = require('../common-utils.js');
var nextTick = (typeof process === 'undefined' || process.browser) ?
setTimeout : process.nextTick;

var grep;
var iterations;
const params = commonUtils.params();
if (commonUtils.isNode()) {
grep = params.GREP;
iterations = params.ITERATIONS && parseInt(params.ITERATIONS, 10);
} else {
grep = params.grep;
iterations = params.iterations && parseInt(params.iterations, 10);
const grep = commonUtils.isNode() ? params.GREP : params.grep;

function iterationsFor(testCase) {
const override = commonUtils.isNode() ? params.ITERATIONS : params.iterations;
if (override) {
return parseInt(override, 10);
} else {
return testCase.iterations;
}
}

var adapterUsed;
Expand All @@ -28,9 +29,7 @@ exports.runTests = function (PouchDB, suiteName, testCases, callback) {
return false;
}
}
var iter = typeof iterations === 'number' ? iterations :
testCase.iterations;
return iter !== 0;
return iterationsFor(testCase) > 0;
});

if (!testCases.length) {
Expand All @@ -39,18 +38,18 @@ exports.runTests = function (PouchDB, suiteName, testCases, callback) {

testCases.forEach(function (testCase, i) {
var testName = testCase.name;
var iter = typeof iterations === 'number' ? iterations :
testCase.iterations;
test('benchmarking', function (t) {
var db;
var setupObj;

var localDbName = commonUtils.safeRandomDBName();

const iterations = iterationsFor(testCase);

t.test('setup', function (t) {
db = new PouchDB(localDbName, { size: 3000 });
adapterUsed = db.adapter;
testCase.setup(db, function (err, res) {
testCase.setup(db, { iterations }, function (err, res) {
if (err) {
t.error(err);
reporter.log(testName + ' errored: ' + err.message + '\n');
Expand All @@ -59,7 +58,7 @@ exports.runTests = function (PouchDB, suiteName, testCases, callback) {
if (i === 0) {
reporter.startSuite(suiteName);
}
reporter.start(testCase, iter);
reporter.start(testCase, iterations);
t.end();
});
});
Expand All @@ -83,7 +82,7 @@ exports.runTests = function (PouchDB, suiteName, testCases, callback) {
} else {
reporter.endIteration(testCase);
}
if (++num < iter) {
if (++num < iterations) {
next();
} else {
t.ok(testName + ' completed');
Expand Down

0 comments on commit 5ae99dd

Please sign in to comment.