Skip to content

Commit 00fae09

Browse files
committed
add close test
1 parent 792f5c7 commit 00fae09

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,4 @@ module.exports = class Hyperblobs {
7575
this.monitors.add(monitor)
7676
return monitor
7777
}
78-
79-
// closeMonitors () {
80-
// const closing = []
81-
// for (const monitor of this.monitors) closing.push(monitor.close())
82-
// await Promise.allSettled(closing)
83-
// }
8478
}

test/all.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,18 @@ test('upload/download can be monitored', async (t) => {
363363
t.alike(controRes, buf)
364364
})
365365

366-
// test('monitor is removed from the Set on close', async (t) => {
367-
// const { drive } = await testenv(t)
368-
// const monitor = drive.monitor('/example.md')
369-
// await monitor.ready()
370-
// t.is(drive.monitors.size, 1)
371-
// await monitor.close()
372-
// t.is(drive.monitors.size, 0)
373-
// })
366+
test('monitor is removed from the Set on close', async (t) => {
367+
const core = new Hypercore(RAM)
368+
const blobs = new Hyperblobs(core)
369+
370+
const bytes = 1024 * 100 // big enough to trigger more than one update event
371+
const buf = Buffer.alloc(bytes, '0')
372+
const id = await blobs.put(buf)
373+
const monitor = blobs.monitor(id)
374+
t.is(blobs.monitors.size, 1)
375+
await monitor.close()
376+
t.is(blobs.monitors.size, 0)
377+
})
374378

375379
async function createPair () {
376380
const a = new Hypercore(RAM)

0 commit comments

Comments
 (0)