Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit e546575

Browse files
committed
Test accessing an iterator after db.close()
1 parent aba99ca commit e546575

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/cleanup-hanging-iterators-test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,37 @@ makeTest('test legacy ended iterators', function (db, t, done) {
103103
done()
104104
})
105105
})
106+
107+
makeTest('test accessing an iterator after close', function (db, t, done) {
108+
var it = db.iterator({ highWaterMark: 0 })
109+
110+
db.close(function (err) {
111+
t.ifError(err, 'no error from close()')
112+
113+
// Because we have a reference here, the iterator is not GC-ed yet, only
114+
// ended. The object should still be safe to access.
115+
it.next(function (err) {
116+
t.is(err.message, 'iterator has ended')
117+
done(null, false)
118+
})
119+
})
120+
})
121+
122+
makeTest('test accessing an iterator after close and reopen', function (db, t, done) {
123+
var it = db.iterator({ highWaterMark: 0 })
124+
125+
db.close(function (err) {
126+
t.ifError(err, 'no error from close()')
127+
128+
db.open(function (err) {
129+
t.ifError(err, 'no error from open()')
130+
131+
// The state of an iterator should not be tied to the open-state of the
132+
// database, but to the singular database "life" of when it was created.
133+
it.next(function (err) {
134+
t.is(err.message, 'iterator has ended')
135+
done()
136+
})
137+
})
138+
})
139+
})

0 commit comments

Comments
 (0)