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

Commit fabf2e2

Browse files
committed
Test edge cases
1 parent 50b3303 commit fabf2e2

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

test/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,86 @@ test('SubDb main function', function (t) {
172172
})
173173
})
174174

175+
t.test('wrap opened levelup, close levelup and sublevel', function (t) {
176+
t.plan(3)
177+
178+
levelup(memdown(), function (err, db) {
179+
t.ifError(err, 'no open error')
180+
var sub = subdb(db, 'test')
181+
182+
sub.once('open', function () {
183+
db.close(function (err) {
184+
t.ifError(err, 'no close error')
185+
})
186+
187+
// Technically not needed, but shouldn't error
188+
sub.close(function (err) {
189+
t.ifError(err, 'no close error')
190+
})
191+
})
192+
})
193+
})
194+
195+
t.test('wrap opened levelup, close levelup and sublevel while sublevel is opening', function (t) {
196+
t.plan(7)
197+
198+
levelup(memdown(), function (err, db) {
199+
t.ifError(err, 'no open error')
200+
var sub = subdb(db, 'test')
201+
202+
db.close(function (err) {
203+
t.ifError(err, 'no close error')
204+
t.is(reachdown(sub, 'subleveldown').status, 'opening') // TODO
205+
t.is(reachdown(sub).status, 'closed')
206+
})
207+
208+
// Technically not needed, but shouldn't error
209+
sub.close(function (err) {
210+
t.ifError(err, 'no close error')
211+
t.is(reachdown(sub, 'subleveldown').status, 'closed')
212+
t.is(reachdown(sub).status, 'closed')
213+
})
214+
})
215+
})
216+
217+
t.test('wrap opened levelup, close levelup while sublevel is opening', function (t) {
218+
t.plan(4)
219+
220+
levelup(memdown(), function (err, db) {
221+
t.ifError(err, 'no open error')
222+
var sub = subdb(db, 'test')
223+
224+
db.close(function (err) {
225+
t.ifError(err, 'no close error')
226+
t.is(reachdown(sub, 'subleveldown').status, 'opening') // TODO
227+
t.is(reachdown(sub).status, 'closed')
228+
})
229+
})
230+
})
231+
232+
t.test('wrap closing levelup', function (t) {
233+
t.plan(7)
234+
235+
levelup(memdown(), function (err, db) {
236+
t.ifError(err, 'no open error')
237+
238+
db.close(function (err) {
239+
t.ifError(err, 'no close error')
240+
t.is(reachdown(sub, 'subleveldown').status, 'opening')
241+
t.is(reachdown(sub).status, 'opening')
242+
243+
sub.on('open', function (err) {
244+
t.ifError(err, 'no open error')
245+
t.is(reachdown(sub, 'subleveldown').status, 'open')
246+
t.is(reachdown(sub).status, 'open')
247+
})
248+
})
249+
250+
// Perhaps this should throw instead? It's funky
251+
var sub = subdb(db, 'test')
252+
})
253+
})
254+
175255
t.test('wrap levelup and encoding-down, close sublevel and re-open', function (t) {
176256
t.plan(3)
177257
var db = levelup(encoding(memdown()))

0 commit comments

Comments
 (0)