Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close dbs #167

Merged
merged 9 commits into from
Dec 23, 2017
7 changes: 5 additions & 2 deletions abstract/approximate-size-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,7 +68,6 @@ module.exports.args = function (test) {
})

test('test custom _serialize*', function (t) {
t.plan(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 on removing t.plan(3) because it asserts that db._approximateSize is indeed called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll fix.

var db = leveldown(testCommon.location())
db._serializeKey = function (data) { return data }
db._approximateSize = function (start, end, callback) {
Expand All @@ -79,6 +78,10 @@ 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()
})
})
})
})
Expand Down
9 changes: 6 additions & 3 deletions abstract/del-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ module.exports.args = function (test) {
})

test('test custom _serialize*', function (t) {
t.plan(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

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()
})
})
})
})
Expand All @@ -63,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woa, nice catch.

t.ok(err, 'entry propertly deleted')
t.ok(typeof value === 'undefined', 'value is undefined')
t.ok(verifyNotFoundError(err), 'NotFound error')
Expand Down
7 changes: 5 additions & 2 deletions abstract/get-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ module.exports.args = function (test) {
})

test('test custom _serialize*', function (t) {
t.plan(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

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()
})
})
})
})
Expand Down
9 changes: 6 additions & 3 deletions abstract/put-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,28 @@ 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)
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do the .close() dance here since .open() is never called.

})

test('test custom _serialize*', function (t) {
t.plan(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

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()
})
})
})
})
Expand Down
5 changes: 3 additions & 2 deletions testCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var lastLocation = function () {
}

var cleanup = function (callback) {
if (process.browser) { return callback() }
if (process.browser) { return process.nextTick(callback) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


fs.readdir(__dirname, function (err, list) {
if (err) return callback(err)
Expand All @@ -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() }
})
})
Expand Down