Skip to content

Commit 25a0d0d

Browse files
committed
fix memory usage test using memoryUSage().arrayBuffers when available
1 parent 6863c4b commit 25a0d0d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/binary.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ describe('binary', () => {
5252
return Streamer
5353
}
5454

55+
const snapshotBufferMemoryUsage = function () {
56+
const mu = process.memoryUsage()
57+
const mem = mu.arrayBuffers || mu.external
58+
return mem / 1024 / 1024
59+
}
60+
5561
it('low copy-to memory usage during large bytea streaming', (done) => {
5662
const power = 26
5763
const sql = "COPY (select (repeat('-', CAST(2^" + power + ' AS int)))::bytea) TO STDOUT BINARY'
@@ -63,7 +69,7 @@ describe('binary', () => {
6369
write(chunk, enc, cb) {
6470
if (Math.random() < 0.02) {
6571
global.gc()
66-
const memNow = process.memoryUsage().external / 1024 / 1024
72+
const memNow = snapshotBufferMemoryUsage()
6773
try {
6874
const memLimit = 32 /*MB*/
6975
const memDiff = Math.abs(memNow - memStart)
@@ -89,7 +95,7 @@ describe('binary', () => {
8995
})
9096

9197
global.gc(true)
92-
const memStart = process.memoryUsage().external / 1024 / 1024
98+
const memStart = snapshotBufferMemoryUsage()
9399
const stream = client.query(query).pipe(lfs).pipe(noop)
94100

95101
stream.on('error', (err) => {

0 commit comments

Comments
 (0)