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 bca0eac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/fetch-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ test('do not leak', (t) => {
.then(attack)
})

const xs = []
let prev = Infinity
let count = 0
const interval = setInterval(() => {
done = true
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 bca0eac

Please sign in to comment.