Aktueller Stand
This commit is contained in:
89
backend/node_modules/fastify/test/close-pipelining.test.js
generated
vendored
89
backend/node_modules/fastify/test/close-pipelining.test.js
generated
vendored
@@ -1,10 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const Fastify = require('..')
|
||||
const { Client } = require('undici')
|
||||
const semver = require('semver')
|
||||
|
||||
test('Should return 503 while closing - pipelining', async t => {
|
||||
const fastify = Fastify({
|
||||
@@ -13,46 +11,10 @@ test('Should return 503 while closing - pipelining', async t => {
|
||||
})
|
||||
|
||||
fastify.get('/', async (req, reply) => {
|
||||
fastify.close()
|
||||
return { hello: 'world' }
|
||||
})
|
||||
|
||||
await fastify.listen({ port: 0 })
|
||||
|
||||
const instance = new Client('http://localhost:' + fastify.server.address().port, {
|
||||
pipelining: 2
|
||||
})
|
||||
|
||||
const codes = [200, 200, 503]
|
||||
const responses = await Promise.all([
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' })
|
||||
])
|
||||
const actual = responses.map(r => r.statusCode)
|
||||
|
||||
t.same(actual, codes)
|
||||
|
||||
await instance.close()
|
||||
})
|
||||
|
||||
// default enable of idle closing idle connection is accidentally backported to 18.19.0 and fixed in 18.20.3
|
||||
// Refs: https://github.com/nodejs/node/releases/tag/v18.20.3
|
||||
const isNodeDefaultClosingIdleConnection =
|
||||
(
|
||||
semver.gte(process.version, '18.19.0') &&
|
||||
semver.lt(process.version, '18.20.3')
|
||||
) ||
|
||||
semver.gte(process.version, '19.0.0')
|
||||
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip when Node default closing idle connection', { skip: isNodeDefaultClosingIdleConnection }, async t => {
|
||||
const fastify = Fastify({
|
||||
return503OnClosing: false,
|
||||
forceCloseConnections: false
|
||||
})
|
||||
|
||||
fastify.get('/', (req, reply) => {
|
||||
fastify.close()
|
||||
// Simulate a delay to allow pipelining to kick in
|
||||
await new Promise(resolve => setTimeout(resolve, 5))
|
||||
reply.send({ hello: 'world' })
|
||||
fastify.close()
|
||||
})
|
||||
|
||||
await fastify.listen({ port: 0 })
|
||||
@@ -61,21 +23,25 @@ test('Should not return 503 while closing - pipelining - return503OnClosing: fal
|
||||
pipelining: 2
|
||||
})
|
||||
|
||||
const codes = [200, 200, 200]
|
||||
const responses = await Promise.all([
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' })
|
||||
const [firstRequest, secondRequest, thirdRequest] = await Promise.allSettled([
|
||||
instance.request({ path: '/', method: 'GET', blocking: false }),
|
||||
instance.request({ path: '/', method: 'GET', blocking: false }),
|
||||
instance.request({ path: '/', method: 'GET', blocking: false })
|
||||
])
|
||||
const actual = responses.map(r => r.statusCode)
|
||||
t.assert.strictEqual(firstRequest.status, 'fulfilled')
|
||||
t.assert.strictEqual(secondRequest.status, 'fulfilled')
|
||||
|
||||
t.same(actual, codes)
|
||||
t.assert.strictEqual(firstRequest.value.statusCode, 200)
|
||||
t.assert.strictEqual(secondRequest.value.statusCode, 200)
|
||||
|
||||
t.assert.strictEqual(thirdRequest.status, 'fulfilled')
|
||||
t.assert.strictEqual(thirdRequest.value.statusCode, 503)
|
||||
|
||||
await instance.close()
|
||||
})
|
||||
|
||||
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip when Node not default closing idle connection', { skip: !isNodeDefaultClosingIdleConnection }, async t => {
|
||||
// Since Node v19, we will always invoke server.closeIdleConnections()
|
||||
test('Should close the socket abruptly - pipelining - return503OnClosing: false', async t => {
|
||||
// Since Node v20, we will always invoke server.closeIdleConnections()
|
||||
// therefore our socket will be closed
|
||||
const fastify = Fastify({
|
||||
return503OnClosing: false,
|
||||
@@ -83,6 +49,8 @@ test('Should close the socket abruptly - pipelining - return503OnClosing: false,
|
||||
})
|
||||
|
||||
fastify.get('/', async (req, reply) => {
|
||||
// Simulate a delay to allow pipelining to kick in
|
||||
await new Promise(resolve => setTimeout(resolve, 5))
|
||||
reply.send({ hello: 'world' })
|
||||
fastify.close()
|
||||
})
|
||||
@@ -90,20 +58,21 @@ test('Should close the socket abruptly - pipelining - return503OnClosing: false,
|
||||
await fastify.listen({ port: 0 })
|
||||
|
||||
const instance = new Client('http://localhost:' + fastify.server.address().port, {
|
||||
pipelining: 2
|
||||
pipelining: 1
|
||||
})
|
||||
|
||||
const responses = await Promise.allSettled([
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' }),
|
||||
instance.request({ path: '/', method: 'GET' })
|
||||
instance.request({ path: '/', method: 'GET', blocking: false }),
|
||||
instance.request({ path: '/', method: 'GET', blocking: false }),
|
||||
instance.request({ path: '/', method: 'GET', blocking: false }),
|
||||
instance.request({ path: '/', method: 'GET', blocking: false })
|
||||
])
|
||||
|
||||
t.equal(responses[0].status, 'fulfilled')
|
||||
t.equal(responses[1].status, 'fulfilled')
|
||||
t.equal(responses[2].status, 'rejected')
|
||||
t.equal(responses[3].status, 'rejected')
|
||||
const fulfilled = responses.filter(r => r.status === 'fulfilled')
|
||||
const rejected = responses.filter(r => r.status === 'rejected')
|
||||
|
||||
t.assert.strictEqual(fulfilled.length, 1)
|
||||
t.assert.strictEqual(rejected.length, 3)
|
||||
|
||||
await instance.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user