Home / File/ closing.test.js — fastify Source File

closing.test.js — fastify Source File

Architecture documentation for closing.test.js, a javascript file in the fastify codebase.

Entity Profile

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('../..')
const http2 = require('node:http2')
const { promisify } = require('node:util')
const connect = promisify(http2.connect)
const { once } = require('node:events')
const { buildCertificate } = require('../build-certificate')
const { getServerUrl } = require('../helper')
const { kHttp2ServerSessions } = require('../../lib/symbols')

test.before(buildCertificate)

const isNode24OrGreater = Number(process.versions.node.split('.')[0]) >= 24

test('http/2 request while fastify closing Node <24', { skip: isNode24OrGreater }, (t, done) => {
  const fastify = Fastify({
    http2: true
  })
  t.assert.ok('http2 successfully loaded')

  fastify.get('/', () => Promise.resolve({}))

  t.after(() => { fastify.close() })
  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    const url = getServerUrl(fastify)
    const session = http2.connect(url, function () {
      this.request({
        ':method': 'GET',
        ':path': '/'
      }).on('response', headers => {
        t.assert.strictEqual(headers[':status'], 503)
        done()
        this.destroy()
      }).on('error', () => {
        // Nothing to do here,
        // we are not interested in this error that might
        // happen or not
      })
      session.on('error', () => {
        // Nothing to do here,
        // we are not interested in this error that might
        // happen or not
        done()
      })
      fastify.close()
    })
  })
})

test('http/2 request while fastify closing Node >=24', { skip: !isNode24OrGreater }, (t, done) => {
  const fastify = Fastify({
    http2: true
  })
  t.assert.ok('http2 successfully loaded')

  fastify.get('/', () => Promise.resolve({}))
// ... (211 more lines)

Frequently Asked Questions

What does closing.test.js do?
closing.test.js is a source file in the fastify codebase, written in javascript.
Where is closing.test.js in the architecture?
closing.test.js is located at test/http2/closing.test.js (directory: test/http2).

Analyze Your Own Codebase

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

Try Supermodel Free