Skip to content

Commit 16a4dd5

Browse files
committed
Test that stream keeps a reference to the iterator
1 parent 0321343 commit 16a4dd5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ test('values=false', function (t) {
291291
})
292292
})
293293

294+
// It's important to keep a reference to the iterator at least until we end,
295+
// to prevent GC of the iterator and therefor its db (esp. for native addons).
296+
test('keeps a reference to the iterator', function (t) {
297+
var it = db.iterator()
298+
var stream = iteratorStream(it)
299+
300+
stream.on('close', function () {
301+
t.is(stream._iterator, it, 'has reference')
302+
t.end()
303+
})
304+
305+
stream.resume()
306+
})
307+
294308
function monitor (iterator, stream, onClose) {
295309
var order = []
296310

0 commit comments

Comments
 (0)