Skip to content

Commit

Permalink
Test reopening a sublevel (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Oct 3, 2019
1 parent c488d12 commit f9d4e03
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ test('SubDb main function', function (t) {
})
})

t.test('wrap levelup and encoding-down, close sublevel and re-open', function (t) {
t.plan(3)
var db = levelup(encoding(memdown()))

db.once('open', function () {
var sub = subdb(db, 'test')

sub.close(function (err) {
t.ifError(err, 'no close error')

// Previously, subleveldown would open a sublevel via levelup yet close
// it via the innermost db (memdown). So at this point, the intermediate
// encoding-down layer would still be open, leading levelup to believe
// that encoding-down and its underlying memdown db need not be opened.
// See https://github.com/Level/subleveldown/issues/60.
sub.open(function (err) {
t.error(err, 'no open error')
t.is(reachdown(sub).status, 'open')
})
})
})
})

t.test('wrapping a sub level', function (t) {
var db = levelup(memdown())
var sub1 = subdb(db, 'test1')
Expand Down

0 comments on commit f9d4e03

Please sign in to comment.