Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate a batch of tests to node test runner no. 8 #2744

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 223 additions & 157 deletions test/client-pipeline.js

Large diffs are not rendered by default.

226 changes: 125 additions & 101 deletions test/client-pipelining.js

Large diffs are not rendered by default.

57 changes: 33 additions & 24 deletions test/client-timeout.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
'use strict'

const { test } = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { Client, errors } = require('..')
const { createServer } = require('node:http')
const { Readable } = require('node:stream')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/timers')

test('refresh timeout on pause', (t) => {
t.plan(1)
test('refresh timeout on pause', async (t) => {
t = tspl(t, { plan: 1 })

const server = createServer((req, res) => {
res.flushHeaders()
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 500
})
t.teardown(client.destroy.bind(client))
after(() => client.destroy())

client.dispatch({
path: '/',
Expand All @@ -44,30 +45,32 @@ test('refresh timeout on pause', (t) => {
}
})
})

await t.completed
})

test('start headers timeout after request body', (t) => {
t.plan(2)
test('start headers timeout after request body', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))
const clock = FakeTimers.install({ shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Object.assign(timers, { setTimeout, clearTimeout })
t.teardown(() => {
after(() => {
Object.assign(timers, orgTimers)
})

const server = createServer((req, res) => {
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 0,
headersTimeout: 100
})
t.teardown(client.destroy.bind(client))
after(() => client.destroy())

const body = new Readable({ read () {} })
client.dispatch({
Expand Down Expand Up @@ -100,30 +103,32 @@ test('start headers timeout after request body', (t) => {
}
})
})

await t.completed
})

test('start headers timeout after async iterator request body', (t) => {
t.plan(1)
test('start headers timeout after async iterator request body', async (t) => {
t = tspl(t, { plan: 1 })

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))
const clock = FakeTimers.install({ shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Object.assign(timers, { setTimeout, clearTimeout })
t.teardown(() => {
after(() => {
Object.assign(timers, orgTimers)
})

const server = createServer((req, res) => {
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 0,
headersTimeout: 100
})
t.teardown(client.destroy.bind(client))
after(() => client.destroy())
let res
const body = (async function * () {
await new Promise((resolve) => { res = resolve })
Expand Down Expand Up @@ -157,21 +162,23 @@ test('start headers timeout after async iterator request body', (t) => {
}
})
})

await t.completed
})

test('parser resume with no body timeout', (t) => {
t.plan(1)
test('parser resume with no body timeout', async (t) => {
t = tspl(t, { plan: 1 })

const server = createServer((req, res) => {
res.end('asd')
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 0
})
t.teardown(client.destroy.bind(client))
after(() => client.destroy())

client.dispatch({
path: '/',
Expand All @@ -190,8 +197,10 @@ test('parser resume with no body timeout', (t) => {
t.ok(true, 'pass')
},
onError (err) {
t.error(err)
t.ifError(err)
}
})
})

await t.completed
})
Loading
Loading