forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto cleanup of open iterators on db.close()
closes facebook#22
- Loading branch information
Showing
8 changed files
with
189 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, leveldown = require('../') | ||
|
||
, makeTest = function (name, testFn) { | ||
test(name, function (t) { | ||
testCommon.cleanup(function () { | ||
var db = leveldown(testCommon.location()) | ||
, done = function () { | ||
db.close(function (err) { | ||
t.notOk(err, 'no error from close()') | ||
testCommon.cleanup(t.end.bind(t)) | ||
}) | ||
} | ||
db.open(function (err) { | ||
t.notOk(err, 'no error from open()') | ||
db.batch( | ||
[ | ||
{ type: 'put', key: 'one', value: '1' } | ||
, { type: 'put', key: 'two', value: '2' } | ||
, { type: 'put', key: 'three', value: '3' } | ||
] | ||
, function (err) { | ||
t.notOk(err, 'no error from batch()') | ||
testFn(db, t, done) | ||
} | ||
) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
makeTest('test ended iterator', function (db, t, done) { | ||
// standard iterator with an end() properly called, easy | ||
|
||
var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) | ||
it.next(function (err, key, value) { | ||
t.notOk(err, 'no error from next()') | ||
t.equal(key, 'one', 'correct key') | ||
t.equal(value, '1', 'correct value') | ||
it.end(function (err) { | ||
t.notOk(err, 'no error from next()') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
makeTest('test non-ended iterator', function (db, t, done) { | ||
// no end() call on our iterator, cleanup should crash Node if not handled properly | ||
var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false }) | ||
it.next(function (err, key, value) { | ||
t.notOk(err, 'no error from next()') | ||
t.equal(key, 'one', 'correct key') | ||
t.equal(value, '1', 'correct value') | ||
done() | ||
}) | ||
}) | ||
|
||
makeTest('test multiple non-ended iterators', function (db, t, done) { | ||
// no end() call on our iterator, cleanup should crash Node if not handled properly | ||
db.iterator() | ||
db.iterator().next(function () {}) | ||
db.iterator().next(function () {}) | ||
db.iterator().next(function () {}) | ||
setTimeout(done, 50) | ||
}) | ||
|
||
makeTest('test ending iterators', function (db, t, done) { | ||
// no end() call on our iterator, cleanup should crash Node if not handled properly | ||
var it1 = db.iterator().next(function () { | ||
it1.end(function () {}) | ||
}) | ||
, it2 = db.iterator().next(function () { | ||
it2.end(function () {}) | ||
done() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters