Skip to content

Commit 0ecaa63

Browse files
committed
test: pin socket highWaterMark in chunked drain test
The default stream highWaterMark is 16 KiB on Windows and 64 KiB elsewhere. With the smaller value the fake socket exceeds its own highWaterMark in UTF-16 code units and emits 'drain' by itself before the write callback destroys the response, which trips mustNotCall(). Pin the highWaterMark so the payload sizes stay on the intended side of it on every platform, and assert that the socket never drains on its own in the destroy scenario. Refs: #66782 (comment) Assisted-by: AI coding agent Signed-off-by: junyup0503 <[email protected]>
1 parent 3f263a8 commit 0ecaa63

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎test/parallel/test-http-outgoing-chunked-drain-multibyte.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ const { Duplex } = require('stream');
1313

1414
// Behaves like net.Socket for this purpose: strings are counted in UTF-16
1515
// code units and writes complete asynchronously, so flushed data is still in
16-
// flight when uncork() returns.
16+
// flight when uncork() returns. The high water mark is pinned because the
17+
// default is platform dependent (16 KiB on Windows), and the coalesced
18+
// payloads below must exceed it in bytes while staying under it in code
19+
// units, so that the socket never emits 'drain' on its own.
1720
function createSocket() {
1821
const pending = [];
1922
const socket = new Duplex({
2023
decodeStrings: false,
24+
writableHighWaterMark: 64 * 1024,
2125
read() {},
2226
write(chunk, encoding, callback) {
2327
pending.push(callback);
@@ -56,9 +60,11 @@ const row = 'a'.repeat(100) + 'ع'.repeat(150) + '\n'; // 401 bytes
5660
}
5761

5862
// 'drain' must not be emitted once the response has been destroyed from a
59-
// write callback.
63+
// write callback. The socket stays below its own high water mark, so the
64+
// only candidate emitter is the message itself.
6065
{
6166
const socket = createSocket();
67+
socket.on('drain', common.mustNotCall());
6268
const server = http.createServer(common.mustCall((req, res) => {
6369
res.on('drain', common.mustNotCall());
6470
const ret = res.write(row.repeat(200), common.mustCall(() => {

0 commit comments

Comments
 (0)