undici client write max listeners
"use strict"

const { test } = require("tap")
const { Client } = require("..")
const { createServer } = require("http")
const { Readable } = require("stream")

test("socket close listener does not leak", (t) => {
  t.plan(32)

  const server = createServer()

  server.on("request", (req, res) => {
    res.end("hello")
  })
  t.teardown(server.close.bind(server))

  const makeBody = () => {
    return new Readable({
      read () {
        process.nextTick(() => {
          this.push(null)
        })
      }
    })
  }

  const onRequest = (err, data) => {
    t.error(err)
    data.body.on("end", () => t.pass()).resume()
  }

  function onWarning (warning) {
    if (!/ExperimentalWarning/.test(warning)) {
      t.fail()
    }
  }
  process.on("warning", onWarning)
  t.teardown(() => {
    process.removeListener("warning", onWarning)
  })

  server.listen(0, () => {
    const client = new Client(`http://localhost:${server.address().port}`)
    t.teardown(client.destroy.bind(client))

    for (let n = 0; n < 16; ++n) {
      client.request({ path: "/", method: "GET", body: makeBody() }, onRequest)
    }
  })
})

Related articles

undici mock agent.test

import {expectAssignable, expectType} from "tsd"import {Agent, Dispatcher, MockAgent, MockClient, MockPool, setGlobalDispatcher} from "../.."import {MockInterceptor} from "../../types/mock-interceptor"import MockDispatch = MockInterceptor.MockDispatch

undici client dispatch

"use strict" const { test } = require("tap") const http = require("http") const { Client, Pool, errors } = require("..") const stream = require("stream") test("dispatch invalid opts", (t) => { t.plan(14) const client = new Client("http://localhost

undici formdata

"use strict" const { test } = require("tap") const { FormData, File } = require("../../") const { Blob: ThirdPartyBlob } = require("formdata-node") const { Blob } = require("buffer") test("arg validation", (t) => { const form = new FormData() // c

undici data uri

"use strict" const { test } = require("tap") const { URLSerializer, collectASequenceOfCodePoints, stringPercentDecode, parseMIMEType, collectAnHTTPQuotedString } = require("../../lib/fetch/dataURL") const { fetch } = require("../..") test("ht

undici api

import { Duplex, Readable, Writable } from "stream"import { expectAssignable } from "tsd"import { Dispatcher, request, stream, pipeline, connect, upgrade } from "../.."// requestexpectAssignable<Promise<Dispatcher.ResponseData>>(request(""))expectA

undici dispatcher.test d

import { Duplex, Readable, Writable } from "stream" import { expectAssignable, expectType } from "tsd" import { Dispatcher } from "../.." import { URL } from "url" import { Blob } from "buffer" expectAssignable<Dispatcher>(new Dispatcher()) { const d

undici client timeout

"use strict" const { test } = require("tap") const { Client, errors } = require("..") const { createServer } = require("http") const { Readable } = require("stream") const FakeTimers = require("@sinonjs/fake-timers") test("refresh timeout on pause", (t