Aktueller Stand
This commit is contained in:
68
backend/node_modules/fastify/test/stream.3.test.js
generated
vendored
68
backend/node_modules/fastify/test/stream.3.test.js
generated
vendored
@@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const split = require('split2')
|
||||
const Fastify = require('..')
|
||||
|
||||
test('Destroying streams prematurely', t => {
|
||||
test('Destroying streams prematurely', (t, testDone) => {
|
||||
t.plan(6)
|
||||
|
||||
let fastify = null
|
||||
@@ -18,7 +17,7 @@ test('Destroying streams prematurely', t => {
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
}
|
||||
const stream = require('node:stream')
|
||||
const http = require('node:http')
|
||||
@@ -26,13 +25,14 @@ test('Destroying streams prematurely', t => {
|
||||
// Test that "premature close" errors are logged with level warn
|
||||
logStream.on('data', line => {
|
||||
if (line.res) {
|
||||
t.equal(line.msg, 'stream closed prematurely')
|
||||
t.equal(line.level, 30)
|
||||
t.assert.strictEqual(line.msg, 'stream closed prematurely')
|
||||
t.assert.strictEqual(line.level, 30)
|
||||
testDone()
|
||||
}
|
||||
})
|
||||
|
||||
fastify.get('/', function (request, reply) {
|
||||
t.pass('Received request')
|
||||
t.assert.ok('Received request')
|
||||
|
||||
let sent = false
|
||||
const reallyLongStream = new stream.Readable({
|
||||
@@ -48,26 +48,26 @@ test('Destroying streams prematurely', t => {
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
t.assert.ifError(err)
|
||||
t.after(() => fastify.close())
|
||||
|
||||
const port = fastify.server.address().port
|
||||
|
||||
http.get(`http://localhost:${port}`, function (response) {
|
||||
t.equal(response.statusCode, 200)
|
||||
t.assert.strictEqual(response.statusCode, 200)
|
||||
response.on('readable', function () {
|
||||
response.destroy()
|
||||
})
|
||||
|
||||
// Node bug? Node never emits 'close' here.
|
||||
response.on('aborted', function () {
|
||||
t.pass('Response closed')
|
||||
t.assert.ok('Response closed')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('Destroying streams prematurely should call close method', t => {
|
||||
test('Destroying streams prematurely should call close method', (t, testDone) => {
|
||||
t.plan(7)
|
||||
|
||||
let fastify = null
|
||||
@@ -80,7 +80,7 @@ test('Destroying streams prematurely should call close method', t => {
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
}
|
||||
const stream = require('node:stream')
|
||||
const http = require('node:http')
|
||||
@@ -88,13 +88,13 @@ test('Destroying streams prematurely should call close method', t => {
|
||||
// Test that "premature close" errors are logged with level warn
|
||||
logStream.on('data', line => {
|
||||
if (line.res) {
|
||||
t.equal(line.msg, 'stream closed prematurely')
|
||||
t.equal(line.level, 30)
|
||||
t.assert.strictEqual(line.msg, 'stream closed prematurely')
|
||||
t.assert.strictEqual(line.level, 30)
|
||||
}
|
||||
})
|
||||
|
||||
fastify.get('/', function (request, reply) {
|
||||
t.pass('Received request')
|
||||
t.assert.ok('Received request')
|
||||
|
||||
let sent = false
|
||||
const reallyLongStream = new stream.Readable({
|
||||
@@ -106,30 +106,33 @@ test('Destroying streams prematurely should call close method', t => {
|
||||
}
|
||||
})
|
||||
reallyLongStream.destroy = undefined
|
||||
reallyLongStream.close = () => t.ok('called')
|
||||
reallyLongStream.close = () => {
|
||||
t.assert.ok('called')
|
||||
testDone()
|
||||
}
|
||||
reply.send(reallyLongStream)
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
t.assert.ifError(err)
|
||||
t.after(() => { fastify.close() })
|
||||
|
||||
const port = fastify.server.address().port
|
||||
|
||||
http.get(`http://localhost:${port}`, function (response) {
|
||||
t.equal(response.statusCode, 200)
|
||||
t.assert.strictEqual(response.statusCode, 200)
|
||||
response.on('readable', function () {
|
||||
response.destroy()
|
||||
})
|
||||
// Node bug? Node never emits 'close' here.
|
||||
response.on('aborted', function () {
|
||||
t.pass('Response closed')
|
||||
t.assert.ok('Response closed')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('Destroying streams prematurely should call close method when destroy is not a function', t => {
|
||||
test('Destroying streams prematurely should call close method when destroy is not a function', (t, testDone) => {
|
||||
t.plan(7)
|
||||
|
||||
let fastify = null
|
||||
@@ -142,7 +145,7 @@ test('Destroying streams prematurely should call close method when destroy is no
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
}
|
||||
const stream = require('node:stream')
|
||||
const http = require('node:http')
|
||||
@@ -150,13 +153,13 @@ test('Destroying streams prematurely should call close method when destroy is no
|
||||
// Test that "premature close" errors are logged with level warn
|
||||
logStream.on('data', line => {
|
||||
if (line.res) {
|
||||
t.equal(line.msg, 'stream closed prematurely')
|
||||
t.equal(line.level, 30)
|
||||
t.assert.strictEqual(line.msg, 'stream closed prematurely')
|
||||
t.assert.strictEqual(line.level, 30)
|
||||
}
|
||||
})
|
||||
|
||||
fastify.get('/', function (request, reply) {
|
||||
t.pass('Received request')
|
||||
t.assert.ok('Received request')
|
||||
|
||||
let sent = false
|
||||
const reallyLongStream = new stream.Readable({
|
||||
@@ -168,24 +171,27 @@ test('Destroying streams prematurely should call close method when destroy is no
|
||||
}
|
||||
})
|
||||
reallyLongStream.destroy = true
|
||||
reallyLongStream.close = () => t.ok('called')
|
||||
reallyLongStream.close = () => {
|
||||
t.assert.ok('called')
|
||||
testDone()
|
||||
}
|
||||
reply.send(reallyLongStream)
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
t.assert.ifError(err)
|
||||
t.after(() => { fastify.close() })
|
||||
|
||||
const port = fastify.server.address().port
|
||||
|
||||
http.get(`http://localhost:${port}`, function (response) {
|
||||
t.equal(response.statusCode, 200)
|
||||
t.assert.strictEqual(response.statusCode, 200)
|
||||
response.on('readable', function () {
|
||||
response.destroy()
|
||||
})
|
||||
// Node bug? Node never emits 'close' here.
|
||||
response.on('aborted', function () {
|
||||
t.pass('Response closed')
|
||||
t.assert.ok('Response closed')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user