@@ -11,6 +11,7 @@ const net = require('net');
11
11
const tls = require ( 'tls' ) ;
12
12
const os = require ( 'os' ) ;
13
13
const fs = require ( 'fs' ) ;
14
+ const { getDefaultHighWaterMark } = require ( 'stream' ) ;
14
15
const { URL } = require ( 'url' ) ;
15
16
16
17
const Sender = require ( '../lib/sender' ) ;
@@ -23,6 +24,10 @@ const {
23
24
} = require ( '../lib/event-target' ) ;
24
25
const { EMPTY_BUFFER , GUID , kListener, NOOP } = require ( '../lib/constants' ) ;
25
26
27
+ const highWaterMark = getDefaultHighWaterMark
28
+ ? getDefaultHighWaterMark ( false )
29
+ : 16 * 1024 ;
30
+
26
31
class CustomAgent extends http . Agent {
27
32
addRequest ( ) { }
28
33
}
@@ -4092,7 +4097,7 @@ describe('WebSocket', () => {
4092
4097
ws . terminate ( ) ;
4093
4098
} ;
4094
4099
4095
- const payload1 = Buffer . alloc ( 15 * 1024 ) ;
4100
+ const payload1 = Buffer . alloc ( highWaterMark - 1024 ) ;
4096
4101
const payload2 = Buffer . alloc ( 1 ) ;
4097
4102
4098
4103
const opts = {
@@ -4107,13 +4112,17 @@ describe('WebSocket', () => {
4107
4112
...Sender . frame ( payload2 , { rsv1 : true , ...opts } )
4108
4113
] ;
4109
4114
4110
- for ( let i = 0 ; i < 399 ; i ++ ) {
4115
+ for ( let i = 0 ; i < 340 ; i ++ ) {
4111
4116
list . push ( list [ list . length - 2 ] , list [ list . length - 1 ] ) ;
4112
4117
}
4113
4118
4119
+ const data = Buffer . concat ( list ) ;
4120
+
4121
+ assert . ok ( data . length > highWaterMark ) ;
4122
+
4114
4123
// 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 ) ;
4117
4126
4118
4127
wss . clients
4119
4128
. values ( )
@@ -4128,8 +4137,8 @@ describe('WebSocket', () => {
4128
4137
4129
4138
ws . on ( 'close' , ( code ) => {
4130
4139
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 ) ;
4133
4142
assert . strictEqual ( messageLengths [ messageLengths . length - 1 ] , 1 ) ;
4134
4143
wss . close ( done ) ;
4135
4144
} ) ;
0 commit comments