MCPcopy
hub / github.com/nodejs/undici / errorAndPipelining

Function errorAndPipelining

test/node-test/client-errors.js:181–233  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

179}
180
181function errorAndPipelining (type) {
182 test(`POST with a ${type} that errors and pipelining 1 should reconnect`, async (t) => {
183 const trackPostWithPlan = type !== consts.STREAM
184 const p = tspl(t, { plan: trackPostWithPlan ? 12 : 8 })
185
186 const server = createServer({ joinDuplicateHeaders: true })
187 installErrorAndReconnectServer(server, p, {
188 contentLength: '42',
189 trackPostWithPlan
190 })
191 t.after(closeServerAsPromise(server))
192
193 server.listen(0, () => {
194 const client = new Client(`http://localhost:${server.address().port}`)
195 t.after(client.destroy.bind(client))
196
197 client.request({
198 path: '/',
199 method: 'POST',
200 headers: {
201 // higher than the length of the string
202 'content-length': 42
203 },
204 opaque: 'asd',
205 body: maybeWrapStream(new Readable({
206 read () {
207 this.push('a string')
208 this.destroy(new Error('kaboom'))
209 }
210 }), type)
211 }, (err, data) => {
212 p.strictEqual(err.message, 'kaboom')
213 p.strictEqual(data.opaque, 'asd')
214 })
215
216 // this will be queued up
217 client.request({ path: '/', method: 'GET', idempotent: false }, (err, { statusCode, headers, body }) => {
218 p.ifError(err)
219 p.strictEqual(statusCode, 200)
220 p.strictEqual(headers['content-type'], 'text/plain')
221 const bufs = []
222 body.on('data', (buf) => {
223 bufs.push(buf)
224 })
225 body.on('end', () => {
226 p.strictEqual('hello', Buffer.concat(bufs).toString('utf8'))
227 })
228 })
229 })
230
231 await p.completed
232 })
233}
234
235errorAndPipelining(consts.STREAM)
236errorAndPipelining(consts.ASYNC_ITERATOR)

Callers 1

client-errors.jsFile · 0.85

Calls 9

createServerFunction · 0.85
closeServerAsPromiseFunction · 0.85
maybeWrapStreamFunction · 0.85
listenMethod · 0.80
requestMethod · 0.45
onMethod · 0.45
pushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…