Skip to content

Commit 2797ff4

Browse files
committed
Compute test table size based on default high water mark
1 parent 77c820e commit 2797ff4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { t, nt, ot } from './test.js' // eslint-disable-line
44
import net from 'net'
55
import fs from 'fs'
66
import crypto from 'crypto'
7+
import stream from 'stream'
78

89
import postgres from '../src/index.js'
910
const delay = ms => new Promise(r => setTimeout(r, ms))
@@ -1919,11 +1920,12 @@ t('Copy read with back-pressure', async() => {
19191920

19201921
// Make sure there are enough rows in the table to fill the buffer
19211922
// so that `CopyDone` message is handled while the socket is paused
1922-
await sql`insert into test select * from generate_series(1,12774)`
1923+
const bufferSize = Math.ceil((stream.getDefaultHighWaterMark || (() => 16384))() / 6)
1924+
await sql`insert into test select * from generate_series(10000,${9999 + bufferSize})`
19231925

19241926
let result = 0
19251927
const readable = await sql`copy test to stdout`.readable()
1926-
readable.on('data', _ => result++)
1928+
readable.on('data', () => result++)
19271929

19281930
// Pause the stream so that the entire buffer fills up
19291931
readable.pause()
@@ -1934,7 +1936,7 @@ t('Copy read with back-pressure', async() => {
19341936
(async() => {
19351937
// Wait until the entire buffer fills up,
19361938
await new Promise(r => readable.on('readable', () => {
1937-
if (readable.readableBuffer.length === 12774)
1939+
if (readable.readableBuffer.length === bufferSize)
19381940
r()
19391941
}))
19401942
// Switch the stream back to flowing mode (allowing it to be consumed)
@@ -1948,7 +1950,7 @@ t('Copy read with back-pressure', async() => {
19481950

19491951
return [
19501952
result,
1951-
12774,
1953+
bufferSize,
19521954
await sql`drop table test`
19531955
]
19541956
})

0 commit comments

Comments
 (0)