CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
client-timeout.test.js39 linesDownload Raw Back to test
1'use strict'2 3const { test } = require('node:test')4const fastify = require('..')({ requestTimeout: 5, http: { connectionsCheckingInterval: 1000 } })5const { connect } = require('node:net')6 7test('requestTimeout should return 408', (t, done) => {8  t.plan(1)9 10  t.after(() => {11    fastify.close()12  })13 14  fastify.post('/', async function (req, reply) {15    await new Promise(resolve => setTimeout(resolve, 100))16    return reply.send({ hello: 'world' })17  })18 19  fastify.listen({ port: 0 }, err => {20    if (err) {21      throw err22    }23 24    let data = Buffer.alloc(0)25    const socket = connect(fastify.server.address().port)26 27    socket.write('POST / HTTP/1.1\r\nHost: example.com\r\nConnection-Length: 1\r\n')28 29    socket.on('data', c => (data = Buffer.concat([data, c])))30    socket.on('end', () => {31      t.assert.strictEqual(32        data.toString('utf-8'),33        'HTTP/1.1 408 Request Timeout\r\nContent-Length: 71\r\nContent-Type: application/json\r\n\r\n{"error":"Request Timeout","message":"Client Timeout","statusCode":408}'34      )35      done()36    })37  })38})39