Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(456) - Cleanup during test runs

  • Loading branch information...
commit 861bd19c4c888ad1490310b85bafc886fa2487ba 1 parent 22b5ac1
@daleharvey daleharvey authored
View
8 tests/test.all_docs.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true, makeDocs: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,12 +27,9 @@ adapters.map(function(adapter) {
qunit('all_docs: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
var origDocs = [
View
8 tests/test.attachments.js
@@ -2,6 +2,7 @@
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true, makeDocs: false */
/*globals readBlob: false, makeBlob: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -30,12 +31,9 @@ adapters.map(function(adapter) {
qunit('attachments: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
var binAttDoc = {
View
9 tests/test.basics.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -24,12 +25,9 @@ adapters.map(function(adapter) {
qunit("basics: " + adapter, {
setup: function() {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("Create a pouch", 1, function() {
@@ -60,7 +58,6 @@ adapters.map(function(adapter) {
});
asyncTest("Modify a doc", 3, function() {
- console.info('testing: Modify a doc');
initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');
db.post({test: "somestuff"}, function (err, info) {
View
8 tests/test.bulk_docs.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true, makeDocs: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -27,12 +28,9 @@ adapters.map(function(adapter) {
qunit('bulk_docs: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
var authors = [
View
8 tests/test.changes.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,12 +27,9 @@ adapters.map(function(adapter) {
QUnit.module("changes: " + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("All changes", function () {
View
8 tests/test.compaction.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true, putTree: false */
/*globals ajax: true, LevelPouch: true, makeDocs: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -25,12 +26,9 @@ adapters.map(function(adapter) {
qunit('compaction: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest('Compation document with no revisions to remove', function() {
View
8 tests/test.conflicts.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,12 +27,9 @@ adapters.map(function(adapter) {
qunit('conflicts: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest('Testing conflicts', function() {
View
8 tests/test.design_docs.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,12 +27,9 @@ adapters.map(function(adapter) {
qunit("design_docs: " + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
var doc = {
View
8 tests/test.get.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false, putTree: false, putBranch: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true, makeDocs: false, strictEqual: false, notStrictEqual: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,12 +27,9 @@ adapters.map(function(adapter) {
qunit('get: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
var origDocs = [
View
8 tests/test.gql.js
@@ -1,5 +1,6 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -23,12 +24,9 @@ adapters.map(function(adapter) {
qunit('gql: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("Test select *", function() {
View
9 tests/test.issue221.js
@@ -1,6 +1,7 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false, strictEqual: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -30,13 +31,9 @@ adapters.map(function(adapters) {
setup: function() {
this.local = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.local);
- Pouch.destroy(this.remote);
- }
- }
+ teardown: cleanupTestDatabases
});
var doc = { _id: '0', integer: 0 };
View
9 tests/test.replication.js
@@ -1,5 +1,6 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, openTestDB: false, putAfter: false */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -33,13 +34,9 @@ adapters.map(function(adapters) {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- Pouch.destroy(this.remote);
- }
- }
+ teardown: cleanupTestDatabases
});
var docs = [
View
9 tests/test.revs_diff.js
@@ -1,10 +1,12 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false */
+/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
+var LevelPouch;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
@@ -24,12 +26,9 @@ adapters.map(function(adapter) {
qunit("revs diff:" + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("Test revs diff", function() {
View
9 tests/test.spatial.js
@@ -1,10 +1,12 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, Spatial: false */
+/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['local-1', 'http-1'];
var qunit = module;
+var LevelPouch;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
@@ -24,12 +26,9 @@ adapters.map(function(adapter) {
qunit('spatial: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
// some geometries are based on the GeoJSON specification
View
9 tests/test.taskqueue.js
@@ -2,6 +2,7 @@
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals ajax: true, LevelPouch: true */
/*globals Pouch: true, QUnit, uuid, asyncTest, ok, start*/
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -24,13 +25,9 @@ adapters.map(function(adapter) {
qunit("taskqueue: " + adapter, {
setup: function() {
this.name = generateAdapterUrl(adapter);
- Pouch.destroy(this.name);
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("Add a doc", 1, function() {
View
71 tests/test.utils.js
@@ -1,7 +1,72 @@
-/*globals extend: false, Buffer: false */
+/*globals extend: false, Buffer: false, Pouch: true */
"use strict";
-var PERSIST_DATABASES = true;
+var PERSIST_DATABASES = false;
+
+function cleanupAllDbs() {
+
+ var deleted = 0;
+ var adapters = Object.keys(Pouch.adapters).filter(function(adapter) {
+ return adapter !== 'http' && adapter !== 'https';
+ });
+
+ function finished() {
+ // Restart text execution
+ start();
+ }
+
+ function dbDeleted() {
+ deleted++;
+ if (deleted === adapters.length) {
+ finished();
+ }
+ }
+
+ if (!adapters.length) {
+ finished();
+ }
+
+ // Remove old allDbs to prevent DOM exception
+ adapters.forEach(function(adapter) {
+ if (adapter === "http" || adapter === "https") {
+ return;
+ }
+ Pouch.destroy(Pouch.allDBName(adapter), dbDeleted);
+ });
+}
+
+function cleanupTestDatabases() {
+
+ if (PERSIST_DATABASES) {
+ return;
+ }
+
+ // Stop the tests from executing
+ stop();
+
+ var dbCount;
+ var deleted = 0;
+
+ function finished() {
+ cleanupAllDbs();
+ }
+
+ function dbDeleted() {
+ if (++deleted === dbCount) {
+ finished();
+ }
+ }
+
+ Pouch.allDbs(function(err, dbs) {
+ if (!dbs.length) {
+ finished();
+ }
+ dbCount = dbs.length;
+ dbs.forEach(function(db) {
+ Pouch.destroy(db, dbDeleted);
+ });
+ });
+}
function uuid() {
var S4 = function() {
@@ -174,7 +239,6 @@ var putTree = function(db, tree, callback) {
insert(0);
};
-
if (typeof module !== 'undefined' && module.exports) {
Pouch = require('../src/pouch.js');
module.exports = {
@@ -190,6 +254,7 @@ if (typeof module !== 'undefined' && module.exports) {
putAfter: putAfter,
putBranch: putBranch,
putTree: putTree,
+ cleanupTestDatabases: cleanupTestDatabases,
PERSIST_DATABASES: PERSIST_DATABASES
};
}
View
9 tests/test.views.js
@@ -1,5 +1,6 @@
/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
+/*globals cleanupTestDatabases: false */
"use strict";
@@ -26,13 +27,9 @@ adapters.map(function(adapter) {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.remote = generateAdapterUrl('local-2');
+ Pouch.enableAllDbs = true;
},
- teardown: function() {
- if (!PERSIST_DATABASES) {
- Pouch.destroy(this.name);
- Pouch.destroy(this.remote);
- }
- }
+ teardown: cleanupTestDatabases
});
asyncTest("Test basic view", function() {
Please sign in to comment.
Something went wrong with that request. Please try again.