Home / Function/ runBadClientCall() — fastify Function Reference

runBadClientCall() — fastify Function Reference

Architecture documentation for the runBadClientCall() function in issue-4959.test.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  a4cc8da5_fe74_a1bf_4612_af99d8edcffd["runBadClientCall()"]
  04b0182b_5df5_dfe0_487c_62e7961da342["issue-4959.test.js"]
  a4cc8da5_fe74_a1bf_4612_af99d8edcffd -->|defined in| 04b0182b_5df5_dfe0_487c_62e7961da342
  style a4cc8da5_fe74_a1bf_4612_af99d8edcffd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

test/issue-4959.test.js lines 14–58

function runBadClientCall (reqOptions, payload, waitBeforeDestroy) {
  let innerResolve, innerReject
  const promise = new Promise((resolve, reject) => {
    innerResolve = resolve
    innerReject = reject
  })

  const postData = JSON.stringify(payload)

  const req = http.request({
    ...reqOptions,
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(postData)
    }
  }, () => {
    innerReject(new Error('Request should have failed'))
  })

  // Kill the socket after the request has been fully written.
  // Destroying it on `connect` can race before any bytes are sent, making the
  // server-side assertions (hooks/handler) non-deterministic.
  //
  // To keep the test deterministic, we optionally wait for a server-side signal
  // (e.g. onSend entered) before aborting the client.
  let socket
  req.on('socket', (s) => { socket = s })
  req.on('finish', () => {
    if (waitBeforeDestroy && typeof waitBeforeDestroy.then === 'function') {
      Promise.race([
        waitBeforeDestroy,
        new Promise(resolve => setTimeout(resolve, 200))
      ]).then(() => {
        if (socket) socket.destroy()
      }, innerResolve)
      return
    }
    setTimeout(() => { socket.destroy() }, 0)
  })
  req.on('error', innerResolve)
  req.write(postData)
  req.end()

  return promise
}

Domain

Subdomains

Frequently Asked Questions

What does runBadClientCall() do?
runBadClientCall() is a function in the fastify codebase, defined in test/issue-4959.test.js.
Where is runBadClientCall() defined?
runBadClientCall() is defined in test/issue-4959.test.js at line 14.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free