Skip to content

Commit

Permalink
test: fix flakyness of issue-803 test (#2960)
Browse files Browse the repository at this point in the history
* test: improve performance of issue-803 test

* increase timeout
  • Loading branch information
Uzlopak authored Mar 14, 2024
1 parent 3e59a2d commit 07019d0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions test/issue-803.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
test('https://github.com/nodejs/undici/issues/803', { timeout: 60000 }, 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()
Expand Down

0 comments on commit 07019d0

Please sign in to comment.