Skip to content
Merged
Changes from all commits
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
14 changes: 8 additions & 6 deletions test/capacity_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ it('Does not increase capacity when there is sufficient capacity', () => {
})

it('Uses exponential doubling capacity scaling', () => {
const res1 = CalculateCapacity(8192, 8193, 1024 * 1024)
assert.deepEqual(res1, [true, 16384])
const res2 = CalculateCapacity(16384, 16385, 1024 * 1024)
assert.deepEqual(res2, [true, 32768])
// Capacities at or above Buffer.poolSize are unaffected by the minimum-capacity
// floor, so these exercise pure doubling regardless of the platform's pool size.
const res1 = CalculateCapacity(Buffer.poolSize, Buffer.poolSize + 1, 1024 * 1024)
assert.deepEqual(res1, [true, Buffer.poolSize * 2])
const res2 = CalculateCapacity(Buffer.poolSize * 2, Buffer.poolSize * 2 + 1, 1024 * 1024)
assert.deepEqual(res2, [true, Buffer.poolSize * 4])
})

it('Uses required capacity when it exceeds doubling', () => {
const [resize, newCapacity] = CalculateCapacity(1024, 16384, 1024 * 1024)
const [resize, newCapacity] = CalculateCapacity(Buffer.poolSize, Buffer.poolSize * 4, 1024 * 1024)
assert.equal(resize, true)
assert.equal(newCapacity, 16384)
assert.equal(newCapacity, Buffer.poolSize * 4)
})

it('Does not exceed max over allocation', () => {
Expand Down
Loading