Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flakyness of issue-803 test #2960

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading