@@ -4,6 +4,7 @@ import { t, nt, ot } from './test.js' // eslint-disable-line
44import net from 'net'
55import fs from 'fs'
66import crypto from 'crypto'
7+ import stream from 'stream'
78
89import postgres from '../src/index.js'
910const 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