Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Apr 8, 2023
1 parent 7312080 commit 29bc2d5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/fetch-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ test('do not leak', (t) => {
.then(attack)
})

const xs = []
let prev = Infinity
let count = 0
const interval = setInterval(() => {
global.gc()
xs.push(process.memoryUsage().heapUsed)
if (xs.length > 5) {
done = true
const final = xs.pop() // compare against final value
xs.splice(2) // skip first two values, memory can still be growing
t.ok(xs.every(x => final - x < 1e6))
const next = process.memoryUsage().heapUsed
if (next <= prev) {
t.pass()
} else if (count++ > 10) {
t.fail()
} else {
prev = next
}
}, 1e3)
t.teardown(() => clearInterval(interval))
Expand Down

0 comments on commit 29bc2d5

Please sign in to comment.