From a34d476d1b1faccb2103e143bb73a392c5619296 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 14 Mar 2024 20:46:17 +0100 Subject: [PATCH 1/2] test: improve performance of issue-803 test --- test/issue-803.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/issue-803.js b/test/issue-803.js index 849bc1aba47..f18083b5851 100644 --- a/test/issue-803.js +++ b/test/issue-803.js @@ -5,22 +5,26 @@ const { test, after } = require('node:test') const { once } = require('node:events') const { Client } = require('..') const { createServer } = require('node:http') -const EE = require('node:events') test('https://github.com/nodejs/undici/issues/803', async (t) => { t = tspl(t, { plan: 2 }) const SIZE = 5900373096 + const chunkSize = 65536 + const parts = (SIZE / chunkSize) | 0 + const lastPartSize = SIZE % chunkSize + const chunk = Buffer.allocUnsafe(chunkSize) const server = createServer(async (req, res) => { res.setHeader('content-length', SIZE) - let pos = 0 - while (pos < SIZE) { - const len = Math.min(SIZE - pos, 65536) - if (!res.write(Buffer.allocUnsafe(len))) { - await EE.once(res, 'drain') + let i = 0 + while (i++ < parts) { + if (res.write(chunk) === false) { + await once(res, 'drain') } - pos += len + } + if (res.write(chunk.subarray(0, lastPartSize)) === false) { + await once(res, 'drain') } res.end() From cfb7fb4573375b242f9e9ac8eb0db736e394bc3c Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 14 Mar 2024 21:05:19 +0100 Subject: [PATCH 2/2] increase timeout --- test/issue-803.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/issue-803.js b/test/issue-803.js index f18083b5851..0ab94cd1d37 100644 --- a/test/issue-803.js +++ b/test/issue-803.js @@ -6,7 +6,7 @@ const { once } = require('node:events') const { Client } = require('..') const { createServer } = require('node:http') -test('https://github.com/nodejs/undici/issues/803', async (t) => { +test('https://github.com/nodejs/undici/issues/803', { timeout: 60000 }, async (t) => { t = tspl(t, { plan: 2 }) const SIZE = 5900373096