Skip to content

Commit

Permalink
Leave some tests on tap
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Jan 11, 2024
1 parent 62dd4ff commit bc36686
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 59 deletions.
38 changes: 38 additions & 0 deletions test/client-connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

const { test } = require('tap')
const { Client, errors } = require('..')
const http = require('http')
const EE = require('events')
const { kBusy } = require('../lib/core/symbols')

// TODO: move to test/node-test/client-connect.js
test('connect aborted after connect', (t) => {
t.plan(3)

const signal = new EE()
const server = http.createServer((req, res) => {
t.fail()
})
server.on('connect', (req, c, firstBodyChunk) => {
signal.emit('abort')
})
t.teardown(server.close.bind(server))

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

client.connect({
path: '/',
signal,
opaque: 'asd'
}, (err, { opaque }) => {
t.equal(opaque, 'asd')
t.type(err, errors.RequestAbortedError)
})
t.equal(client[kBusy], true)
})
})
28 changes: 28 additions & 0 deletions test/client-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const { test } = require('tap')
const { Client } = require('..')
const net = require('net')

// TODO: move to test/node-test/client-connect.js
test('parser error', (t) => {
t.plan(2)

const server = net.createServer()
server.once('connection', (socket) => {
socket.write('asd\n\r213123')
})
t.teardown(server.close.bind(server))

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

client.request({ path: '/', method: 'GET' }, (err) => {
t.ok(err)
client.close((err) => {
t.error(err)
})
})
})
})
33 changes: 0 additions & 33 deletions test/node-test/client-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,3 @@ test('connect invalid signal', async (t) => {

await p.completed
})

test('connect aborted after connect', async (t) => {
const p = tspl(t, { plan: 3 })

const signal = new EE()
const server = http.createServer((req, res) => {
p.ok(0)
})
server.on('connect', (req, c, firstBodyChunk) => {
signal.emit('abort')
})
// FIXME: use closeServerAsPromise
t.after(server.close.bind(server))

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

client.connect({
path: '/',
signal,
opaque: 'asd'
}, (err, { opaque }) => {
p.strictEqual(opaque, 'asd')
p.ok(err instanceof errors.RequestAbortedError)
})
p.strictEqual(client[kBusy], true)
})

await p.completed
})
26 changes: 0 additions & 26 deletions test/node-test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { Client, Pool, errors } = require('../..')
const { createServer } = require('http')
const https = require('https')
const pem = require('https-pem')
const net = require('net')
const { Readable } = require('stream')
const { tspl } = require('@matteo.collina/tspl')

Expand Down Expand Up @@ -840,31 +839,6 @@ test('validate request body', async (t) => {
await p.completed
})

test('parser error', async (t) => {
const p = tspl(t, { plan: 2 })

const server = net.createServer()
server.once('connection', (socket) => {
socket.write('asd\n\r213123')
})
// FIXME: use closeServerAsPromise
t.after(server.close.bind(server))

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

client.request({ path: '/', method: 'GET' }, (err) => {
p.ok(err)
client.close((err) => {
p.ifError(err)
})
})
})

await p.completed
})

function socketFailWrite (type) {
test(`socket fail while writing ${type} request body`, async (t) => {
const p = tspl(t, { plan: 2 })
Expand Down

0 comments on commit bc36686

Please sign in to comment.