Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed May 7, 2024
1 parent 939cf3f commit d94c57b
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 344 deletions.
10 changes: 4 additions & 6 deletions lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const assert = require('node:assert')
const { Readable } = require('./readable')
const { InvalidArgumentError, AbortError } = require('../core/errors')
const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
const util = require('../core/util')
const { getResolveErrorBodyCallback } = require('./util')
const { AsyncResource } = require('node:async_hooks')
Expand Down Expand Up @@ -66,13 +66,11 @@ class RequestHandler extends AsyncResource {

if (this.signal) {
if (this.signal.aborted) {
this.reason = this.signal.reason ?? new AbortError()
this.reason = this.signal.reason ?? new RequestAbortedError()
} else {
this.removeAbortListener = util.addAbortListener(this.signal, () => {
this.reason = this.signal.reason ?? new AbortError()
if (this.res) {
util.destroy(this.res, this.reason)
} else if (this.abort) {
this.reason = this.signal.reason ?? new RequestAbortedError()
if (this.abort) {
this.abort(this.reason)
}
})
Expand Down
78 changes: 39 additions & 39 deletions test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,45 +135,45 @@ test('request hwm', async (t) => {
await t.completed
})

// test('request abort before headers', async (t) => {
// t = tspl(t, { plan: 6 })

// const signal = new EE()
// const server = createServer((req, res) => {
// res.end('hello')
// signal.emit('abort')
// })
// after(() => server.close())

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

// client[kConnect](() => {
// client.request({
// path: '/',
// method: 'GET',
// signal
// }, (err) => {
// t.ok(err instanceof errors.RequestAbortedError)
// t.strictEqual(signal.listenerCount('abort'), 0)
// })
// t.strictEqual(signal.listenerCount('abort'), 1)

// client.request({
// path: '/',
// method: 'GET',
// signal
// }, (err) => {
// t.ok(err instanceof errors.RequestAbortedError)
// t.strictEqual(signal.listenerCount('abort'), 0)
// })
// t.strictEqual(signal.listenerCount('abort'), 2)
// })
// })

// await t.completed
// })
test('request abort before headers', async (t) => {
t = tspl(t, { plan: 6 })

const signal = new EE()
const server = createServer((req, res) => {
res.end('hello')
signal.emit('abort')
})
after(() => server.close())

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

client[kConnect](() => {
client.request({
path: '/',
method: 'GET',
signal
}, (err) => {
t.ok(err instanceof errors.RequestAbortedError)
t.strictEqual(signal.listenerCount('abort'), 0)
})
t.strictEqual(signal.listenerCount('abort'), 1)

client.request({
path: '/',
method: 'GET',
signal
}, (err) => {
t.ok(err instanceof errors.RequestAbortedError)
t.strictEqual(signal.listenerCount('abort'), 0)
})
t.strictEqual(signal.listenerCount('abort'), 2)
})
})

await t.completed
})

test('request body destroyed on invalid callback', async (t) => {
t = tspl(t, { plan: 1 })
Expand Down
280 changes: 140 additions & 140 deletions test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,146 +781,146 @@ test('pool dispatch error', async (t) => {
await t.completed
})

// test('pool request abort in queue', async (t) => {
// t = tspl(t, { plan: 3 })

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

// server.listen(0, async () => {
// const client = new Pool(`http://localhost:${server.address().port}`, {
// connections: 1,
// pipelining: 1
// })
// after(() => client.close())

// client.dispatch({
// path: '/',
// method: 'GET'
// }, {
// onConnect () {
// },
// onHeaders (statusCode, headers) {
// t.strictEqual(statusCode, 200)
// },
// onData (chunk) {
// },
// onComplete () {
// t.ok(true, 'pass')
// },
// onError () {
// }
// })

// const signal = new EventEmitter()
// client.request({
// path: '/',
// method: 'GET',
// signal
// }, (err) => {
// t.strictEqual(err.code, 'UND_ERR_ABORTED')
// })
// signal.emit('abort')
// })

// await t.completed
// })

// test('pool stream abort in queue', async (t) => {
// t = tspl(t, { plan: 3 })

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

// server.listen(0, async () => {
// const client = new Pool(`http://localhost:${server.address().port}`, {
// connections: 1,
// pipelining: 1
// })
// after(() => client.close())

// client.dispatch({
// path: '/',
// method: 'GET'
// }, {
// onConnect () {
// },
// onHeaders (statusCode, headers) {
// t.strictEqual(statusCode, 200)
// },
// onData (chunk) {
// },
// onComplete () {
// t.ok(true, 'pass')
// },
// onError () {
// }
// })

// const signal = new EventEmitter()
// client.stream({
// path: '/',
// method: 'GET',
// signal
// }, ({ body }) => body, (err) => {
// t.strictEqual(err.code, 'UND_ERR_ABORTED')
// })
// signal.emit('abort')
// })

// await t.completed
// })

// test('pool pipeline abort in queue', async (t) => {
// t = tspl(t, { plan: 3 })

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

// server.listen(0, async () => {
// const client = new Pool(`http://localhost:${server.address().port}`, {
// connections: 1,
// pipelining: 1
// })
// after(() => client.close())

// client.dispatch({
// path: '/',
// method: 'GET'
// }, {
// onConnect () {
// },
// onHeaders (statusCode, headers) {
// t.strictEqual(statusCode, 200)
// },
// onData (chunk) {
// },
// onComplete () {
// t.ok(true, 'pass')
// },
// onError () {
// }
// })

// const signal = new EventEmitter()
// client.pipeline({
// path: '/',
// method: 'GET',
// signal
// }, ({ body }) => body).end().on('error', (err) => {
// t.strictEqual(err.code, 'UND_ERR_ABORTED')
// })
// signal.emit('abort')
// })

// await t.completed
// })
test('pool request abort in queue', async (t) => {
t = tspl(t, { plan: 3 })

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

server.listen(0, async () => {
const client = new Pool(`http://localhost:${server.address().port}`, {
connections: 1,
pipelining: 1
})
after(() => client.close())

client.dispatch({
path: '/',
method: 'GET'
}, {
onConnect () {
},
onHeaders (statusCode, headers) {
t.strictEqual(statusCode, 200)
},
onData (chunk) {
},
onComplete () {
t.ok(true, 'pass')
},
onError () {
}
})

const signal = new EventEmitter()
client.request({
path: '/',
method: 'GET',
signal
}, (err) => {
t.strictEqual(err.code, 'UND_ERR_ABORTED')
})
signal.emit('abort')
})

await t.completed
})

test('pool stream abort in queue', async (t) => {
t = tspl(t, { plan: 3 })

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

server.listen(0, async () => {
const client = new Pool(`http://localhost:${server.address().port}`, {
connections: 1,
pipelining: 1
})
after(() => client.close())

client.dispatch({
path: '/',
method: 'GET'
}, {
onConnect () {
},
onHeaders (statusCode, headers) {
t.strictEqual(statusCode, 200)
},
onData (chunk) {
},
onComplete () {
t.ok(true, 'pass')
},
onError () {
}
})

const signal = new EventEmitter()
client.stream({
path: '/',
method: 'GET',
signal
}, ({ body }) => body, (err) => {
t.strictEqual(err.code, 'UND_ERR_ABORTED')
})
signal.emit('abort')
})

await t.completed
})

test('pool pipeline abort in queue', async (t) => {
t = tspl(t, { plan: 3 })

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

server.listen(0, async () => {
const client = new Pool(`http://localhost:${server.address().port}`, {
connections: 1,
pipelining: 1
})
after(() => client.close())

client.dispatch({
path: '/',
method: 'GET'
}, {
onConnect () {
},
onHeaders (statusCode, headers) {
t.strictEqual(statusCode, 200)
},
onData (chunk) {
},
onComplete () {
t.ok(true, 'pass')
},
onError () {
}
})

const signal = new EventEmitter()
client.pipeline({
path: '/',
method: 'GET',
signal
}, ({ body }) => body).end().on('error', (err) => {
t.strictEqual(err.code, 'UND_ERR_ABORTED')
})
signal.emit('abort')
})

await t.completed
})

test('pool stream constructor error destroy body', async (t) => {
t = tspl(t, { plan: 4 })
Expand Down
Loading

0 comments on commit d94c57b

Please sign in to comment.