@@ -11,6 +11,7 @@ const net = require('net');
1111const tls = require ( 'tls' ) ;
1212const os = require ( 'os' ) ;
1313const fs = require ( 'fs' ) ;
14+ const { getDefaultHighWaterMark } = require ( 'stream' ) ;
1415const { URL } = require ( 'url' ) ;
1516
1617const Sender = require ( '../lib/sender' ) ;
@@ -23,6 +24,10 @@ const {
2324} = require ( '../lib/event-target' ) ;
2425const { EMPTY_BUFFER , GUID , kListener, NOOP } = require ( '../lib/constants' ) ;
2526
27+ const highWaterMark = getDefaultHighWaterMark
28+ ? getDefaultHighWaterMark ( false )
29+ : 16 * 1024 ;
30+
2631class CustomAgent extends http . Agent {
2732 addRequest ( ) { }
2833}
@@ -4092,7 +4097,7 @@ describe('WebSocket', () => {
40924097 ws . terminate ( ) ;
40934098 } ;
40944099
4095- const payload1 = Buffer . alloc ( 15 * 1024 ) ;
4100+ const payload1 = Buffer . alloc ( highWaterMark - 1024 ) ;
40964101 const payload2 = Buffer . alloc ( 1 ) ;
40974102
40984103 const opts = {
@@ -4107,13 +4112,17 @@ describe('WebSocket', () => {
41074112 ...Sender . frame ( payload2 , { rsv1 : true , ...opts } )
41084113 ] ;
41094114
4110- for ( let i = 0 ; i < 399 ; i ++ ) {
4115+ for ( let i = 0 ; i < 340 ; i ++ ) {
41114116 list . push ( list [ list . length - 2 ] , list [ list . length - 1 ] ) ;
41124117 }
41134118
4119+ const data = Buffer . concat ( list ) ;
4120+
4121+ assert . ok ( data . length > highWaterMark ) ;
4122+
41144123 // This hack is used because there is no guarantee that more than
4115- // 16 KiB will be sent as a single TCP packet.
4116- push . call ( ws . _socket , Buffer . concat ( list ) ) ;
4124+ // `highWaterMark` bytes will be sent as a single TCP packet.
4125+ push . call ( ws . _socket , data ) ;
41174126
41184127 wss . clients
41194128 . values ( )
@@ -4128,8 +4137,8 @@ describe('WebSocket', () => {
41284137
41294138 ws . on ( 'close' , ( code ) => {
41304139 assert . strictEqual ( code , 1006 ) ;
4131- assert . strictEqual ( messageLengths . length , 402 ) ;
4132- assert . strictEqual ( messageLengths [ 0 ] , 15360 ) ;
4140+ assert . strictEqual ( messageLengths . length , 343 ) ;
4141+ assert . strictEqual ( messageLengths [ 0 ] , highWaterMark - 1024 ) ;
41334142 assert . strictEqual ( messageLengths [ messageLengths . length - 1 ] , 1 ) ;
41344143 wss . close ( done ) ;
41354144 } ) ;
0 commit comments