(#2608) - race condition in sync replication test
diff --git a/lib/adapters/leveldb.js b/lib/adapters/leveldb.js
index 5cd7223..d284c96 100644
--- a/lib/adapters/leveldb.js
+++ b/lib/adapters/leveldb.js
@@ -987,15 +987,19 @@
opts = utils.clone(opts);
var leveldown = opts.db || originalLeveldown;
- if (typeof leveldown.destroy !== 'function') {
- leveldown.destroy = function (name, cb) { cb(); };
+ function callDestroy(name, cb) {
+ if (typeof leveldown.destroy === 'function') {
+ leveldown.destroy(name, cb);
+ } else {
+ process.nextTick(callback);
+ }
}
var dbStore;
if (dbStores.has(leveldown.name)) {
dbStore = dbStores.get(leveldown.name);
} else {
- dbStore = new utils.Map();
+ return callDestroy(name, callback);
}
if (dbStore.has(name)) {
@@ -1004,10 +1008,10 @@
dbStore.get(name).close(function () {
dbStore.delete(name);
- leveldown.destroy(name, callback);
+ callDestroy(name, callback);
});
} else {
- leveldown.destroy(name, callback);
+ callDestroy(name, callback);
}
});
diff --git a/tests/test.sync.js b/tests/test.sync.js
index b537a0e..d373fbd 100644
--- a/tests/test.sync.js
+++ b/tests/test.sync.js
@@ -252,7 +252,7 @@
it('Push and pull changes both fire (issue 2555)', function (done) {
var db = new PouchDB(dbs.name);
var remote = new PouchDB(dbs.remote);
-
+ var correct = false;
db.post({}).then(function () {
return remote.post({});
}).then(function () {
@@ -269,8 +269,12 @@
lastChange.should.not.equal(change.direction);
}
if (++numChanges === 2) {
- done();
+ correct = true;
+ sync.cancel();
}
+ }).on('complete', function () {
+ correct.should.equal(true, 'things happened right');
+ done();
});
});
});