Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
breaking test for fd pool
  • Loading branch information
gmaclennan committed Jul 13, 2023
commit 6663c9857d3144a08649e9b57da390df70a7cb29
50 changes: 26 additions & 24 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,34 +454,36 @@ test('unlink on uncreated file does not reject', async function (t) {
})

test('pool', function (t) {
t.plan(8)
const POOL_SIZE = 2
const RAF_COUNT = 10

t.plan((RAF_COUNT * 2) + 2)

const pool = RAF.createPool(2)
const pool = RAF.createPool(POOL_SIZE)

const a = new RAF(gen(), { pool })
const b = new RAF(gen(), { pool })
const c = new RAF(gen(), { pool })
const rafs = []
let pending = RAF_COUNT

for (let i = 0; i < RAF_COUNT; i++) {
const raf = new RAF(gen(), { pool })
rafs.push(raf)
raf.write(0, Buffer.from('hello'), done)
}

a.write(0, Buffer.from('hello'), function (err) {
function done (err) {
t.absent(err, 'no error')
b.write(0, Buffer.from('hello'), function (err) {
t.absent(err, 'no error')
c.write(0, Buffer.from('hello'), function (err) {
t.absent(err, 'no error')
setTimeout(function () {
t.is(pool.active.length, 2)
const all = [a, b, c]
t.is(all.filter(f => f.suspended).length, 1)

for (const f of all) {
f.read(0, 5, function (_, buf) {
t.alike(buf, Buffer.from('hello'))
})
}
}, 100)
})
})
})
if (--pending !== 0) return
setTimeout(function () {
t.is(pool.active.length, POOL_SIZE)
t.is(rafs.filter(f => f.suspended).length, RAF_COUNT - POOL_SIZE)

for (const f of rafs) {
f.read(0, 5, function (_, buf) {
t.alike(buf, Buffer.from('hello'))
})
}
}, 100)
}
})

test('readonly mode', function (t) {
Expand Down