From 70e64ae4aeb8cf1349cd8763cc0c04a77756849a Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 00:23:10 +0100 Subject: [PATCH 1/9] rimraf should work, callback with error if not --- testCommon.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testCommon.js b/testCommon.js index 8f5063c8..c81c04a5 100644 --- a/testCommon.js +++ b/testCommon.js @@ -27,7 +27,8 @@ var cleanup = function (callback) { var ret = 0 list.forEach(function (f) { - rimraf(path.join(__dirname, f), function () { + rimraf(path.join(__dirname, f), function (err) { + if (err) return callback(err) if (++ret === list.length) { callback() } }) }) From b49e6a392760d475d90306deec19573994994803 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 01:43:12 +0100 Subject: [PATCH 2/9] close db in approximate-size-test --- abstract/approximate-size-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/abstract/approximate-size-test.js b/abstract/approximate-size-test.js index 4c3ad1c6..6ee158d9 100644 --- a/abstract/approximate-size-test.js +++ b/abstract/approximate-size-test.js @@ -3,7 +3,7 @@ var leveldown var testCommon module.exports.setUp = function (_leveldown, test, _testCommon) { - test('setUp common', _testCommon.setUp) + test('setUp common for approximate size', _testCommon.setUp) test('setUp db', function (t) { leveldown = _leveldown testCommon = _testCommon @@ -68,7 +68,6 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { - t.plan(3) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._approximateSize = function (start, end, callback) { @@ -79,6 +78,7 @@ module.exports.args = function (test) { db.open(function () { db.approximateSize({ foo: 'bar' }, { beep: 'boop' }, function (err) { t.error(err) + db.close(t.end.bind(t)) }) }) }) From fc7dcd19c931a90ec7fb286895dc89ef60be76c5 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 14:46:18 +0100 Subject: [PATCH 3/9] assert no error after closing db --- abstract/approximate-size-test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/abstract/approximate-size-test.js b/abstract/approximate-size-test.js index 6ee158d9..5fc43d57 100644 --- a/abstract/approximate-size-test.js +++ b/abstract/approximate-size-test.js @@ -78,7 +78,10 @@ module.exports.args = function (test) { db.open(function () { db.approximateSize({ foo: 'bar' }, { beep: 'boop' }, function (err) { t.error(err) - db.close(t.end.bind(t)) + db.close(function (err) { + t.error(err) + t.end() + }) }) }) }) From 40a11a2ad9be22bab7db4aca9c09cb67d3a774bf Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 14:50:13 +0100 Subject: [PATCH 4/9] avoid zalgo in cleanup --- testCommon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testCommon.js b/testCommon.js index c81c04a5..787eb9fa 100644 --- a/testCommon.js +++ b/testCommon.js @@ -13,7 +13,7 @@ var lastLocation = function () { } var cleanup = function (callback) { - if (process.browser) { return callback() } + if (process.browser) { return process.nextTick(callback) } fs.readdir(__dirname, function (err, list) { if (err) return callback(err) From e685ce7be45e6dff504aeabea96fcca6cd4da0ad Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 15:19:49 +0100 Subject: [PATCH 5/9] close db in custom _serialize test in del-test.js + fix zalgo in ._del --- abstract/del-test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/abstract/del-test.js b/abstract/del-test.js index d3600802..6926fe36 100644 --- a/abstract/del-test.js +++ b/abstract/del-test.js @@ -42,16 +42,19 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { - t.plan(2) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._del = function (key, options, callback) { t.deepEqual(key, { foo: 'bar' }) - callback() + process.nextTick(callback) } db.open(function () { db.del({ foo: 'bar' }, function (err) { t.error(err) + db.close(function (err) { + t.error(err) + t.end() + }) }) }) }) From 060abde98a6844ad73bca3cb837b216303ed6a4e Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 15:23:42 +0100 Subject: [PATCH 6/9] :bug: was using value as a global, add missing parameter --- abstract/del-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abstract/del-test.js b/abstract/del-test.js index 6926fe36..b5ff2505 100644 --- a/abstract/del-test.js +++ b/abstract/del-test.js @@ -66,7 +66,7 @@ module.exports.del = function (test) { t.error(err) db.del('foo', function (err) { t.error(err) - db.get('foo', function (err) { + db.get('foo', function (err, value) { t.ok(err, 'entry propertly deleted') t.ok(typeof value === 'undefined', 'value is undefined') t.ok(verifyNotFoundError(err), 'NotFound error') From 6b3090ea5a74a74f83c4c6abaa08d1720fc052b5 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 15:32:49 +0100 Subject: [PATCH 7/9] close db in custom _serialize test in get-test.js + fix zalgo --- abstract/get-test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/abstract/get-test.js b/abstract/get-test.js index a8473888..f5bd9700 100644 --- a/abstract/get-test.js +++ b/abstract/get-test.js @@ -43,16 +43,19 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { - t.plan(2) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._get = function (key, options, callback) { t.deepEqual(key, { foo: 'bar' }) - callback() + process.nextTick(callback) } db.open(function () { db.get({ foo: 'bar' }, function (err) { t.error(err) + db.close(function (err) { + t.error(err) + t.end() + }) }) }) }) From deb5e5e1bc6b2625ba1cdfa109f0c78b86a65fca Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 16:02:30 +0100 Subject: [PATCH 8/9] close db in custom _serialize test in put-test.js + fix zalgo --- abstract/put-test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/abstract/put-test.js b/abstract/put-test.js index b300c136..36080790 100644 --- a/abstract/put-test.js +++ b/abstract/put-test.js @@ -56,7 +56,7 @@ module.exports.args = function (test) { db._put = function (key, value, opts, callback) { t.ok(key) t.ok(value) - callback() + process.nextTick(callback) } db.put({}, {}, function (err, val) { t.error(err) @@ -64,17 +64,20 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { - t.plan(3) var db = leveldown(testCommon.location()) db._serializeKey = db._serializeValue = function (data) { return data } db._put = function (key, value, options, callback) { t.deepEqual(key, { foo: 'bar' }) t.deepEqual(value, { beep: 'boop' }) - callback() + process.nextTick(callback) } db.open(function () { db.put({ foo: 'bar' }, { beep: 'boop' }, function (err) { t.error(err) + db.close(function (err) { + t.error(err) + t.end() + }) }) }) }) From 77fe1c795f494dec47efb2b6b80eff7203844ffb Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 23 Dec 2017 18:05:46 +0100 Subject: [PATCH 9/9] put back t.plan() in custom _serialize tests --- abstract/approximate-size-test.js | 6 ++---- abstract/del-test.js | 6 ++---- abstract/get-test.js | 6 ++---- abstract/put-test.js | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/abstract/approximate-size-test.js b/abstract/approximate-size-test.js index 5fc43d57..8ae2221b 100644 --- a/abstract/approximate-size-test.js +++ b/abstract/approximate-size-test.js @@ -68,6 +68,7 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { + t.plan(4) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._approximateSize = function (start, end, callback) { @@ -78,10 +79,7 @@ module.exports.args = function (test) { db.open(function () { db.approximateSize({ foo: 'bar' }, { beep: 'boop' }, function (err) { t.error(err) - db.close(function (err) { - t.error(err) - t.end() - }) + db.close(t.error.bind(t)) }) }) }) diff --git a/abstract/del-test.js b/abstract/del-test.js index b5ff2505..825cc19e 100644 --- a/abstract/del-test.js +++ b/abstract/del-test.js @@ -42,6 +42,7 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { + t.plan(3) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._del = function (key, options, callback) { @@ -51,10 +52,7 @@ module.exports.args = function (test) { db.open(function () { db.del({ foo: 'bar' }, function (err) { t.error(err) - db.close(function (err) { - t.error(err) - t.end() - }) + db.close(t.error.bind(t)) }) }) }) diff --git a/abstract/get-test.js b/abstract/get-test.js index f5bd9700..755651e4 100644 --- a/abstract/get-test.js +++ b/abstract/get-test.js @@ -43,6 +43,7 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { + t.plan(3) var db = leveldown(testCommon.location()) db._serializeKey = function (data) { return data } db._get = function (key, options, callback) { @@ -52,10 +53,7 @@ module.exports.args = function (test) { db.open(function () { db.get({ foo: 'bar' }, function (err) { t.error(err) - db.close(function (err) { - t.error(err) - t.end() - }) + db.close(t.error.bind(t)) }) }) }) diff --git a/abstract/put-test.js b/abstract/put-test.js index 36080790..58d9fe75 100644 --- a/abstract/put-test.js +++ b/abstract/put-test.js @@ -64,6 +64,7 @@ module.exports.args = function (test) { }) test('test custom _serialize*', function (t) { + t.plan(4) var db = leveldown(testCommon.location()) db._serializeKey = db._serializeValue = function (data) { return data } db._put = function (key, value, options, callback) { @@ -74,10 +75,7 @@ module.exports.args = function (test) { db.open(function () { db.put({ foo: 'bar' }, { beep: 'boop' }, function (err) { t.error(err) - db.close(function (err) { - t.error(err) - t.end() - }) + db.close(t.error.bind(t)) }) }) })