Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 22, 2021
1 parent 50927b9 commit 1865f18
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 85 deletions.
10 changes: 5 additions & 5 deletions lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Body {

// TODO: Optimize.
const sources = []
for await (const chunk of this.readableNodeStream()) {
for await (const chunk of this.stream) {
// TOOD: max size?
sources.push(chunk)
}
Expand All @@ -94,7 +94,7 @@ class Body {
async buffer () {
// TODO: Optimize.
const sources = []
for await (const chunk of this.readableNodeStream()) {
for await (const chunk of this.stream) {
// TOOD: max size?
sources.push(chunk)
}
Expand All @@ -107,16 +107,16 @@ class Body {
return await blob.arrayBuffer()
}

* [Symbol.asyncIterator] () {
[Symbol.asyncIterator] () {
// TODO: Optimize.
yield * this.readableNodeStream()
return this.stream[Symbol.asyncIterator]()
}

async text () {
// TODO: Optimize.
// TODO: Validate content-type req & res headers?
let ret = ''
for await (const chunk of this.readableNodeStream()) {
for await (const chunk of this.stream) {
// TOOD: max size?
ret += chunk
}
Expand Down
4 changes: 2 additions & 2 deletions test/abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for (const { AbortControllerImpl, controllerName } of controllers) {
client.request({ path: '/', method: 'GET' }, (err, response) => {
t.error(err)
const bufs = []
const stream = response.body.readableNodeStream()
const stream = response.body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -137,7 +137,7 @@ for (const { AbortControllerImpl, controllerName } of controllers) {

client.request({ path: '/', method: 'GET', signal: abortController.signal }, (err, response) => {
t.error(err)
const stream = response.body.readableNodeStream()
const stream = response.body.stream
stream.on('data', () => {
abortController.abort()
})
Expand Down
4 changes: 2 additions & 2 deletions test/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ test('with globalAgent', t => {
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -317,7 +317,7 @@ test('with local agent', t => {
t.equal(headers['content-type'], 'text/plain')
const bufs = []

const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down
14 changes: 7 additions & 7 deletions test/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('async hooks', (t) => {

client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.resume()
t.strictSame(getCurrentTransaction(), null)

Expand All @@ -66,7 +66,7 @@ test('async hooks', (t) => {
client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
t.strictSame(getCurrentTransaction(), { hello: 'world2' })
const stream = body.readableNodeStream()
const stream = body.stream
stream.once('data', () => {
t.pass()
stream.resume()
Expand All @@ -80,7 +80,7 @@ test('async hooks', (t) => {

client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.resume()
t.strictSame(getCurrentTransaction(), null)

Expand All @@ -90,7 +90,7 @@ test('async hooks', (t) => {
t.error(err)
t.strictSame(getCurrentTransaction(), { hello: 'world' })

const stream = body.readableNodeStream()
const stream = body.stream
stream.once('data', () => {
t.pass()
stream.resume()
Expand All @@ -104,7 +104,7 @@ test('async hooks', (t) => {

client.request({ path: '/', method: 'HEAD' }, (err, { statusCode, headers, body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.resume()
t.strictSame(getCurrentTransaction(), null)

Expand All @@ -114,7 +114,7 @@ test('async hooks', (t) => {
t.error(err)
t.strictSame(getCurrentTransaction(), { hello: 'world' })

const stream = body.readableNodeStream()
const stream = body.stream
stream.once('data', () => {
t.pass()
stream.resume()
Expand Down Expand Up @@ -164,7 +164,7 @@ test('async hooks client is destroyed', (t) => {

client.request({ path: '/', method: 'GET' }, (err, { body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.resume()
stream.on('error', (err) => {
t.ok(err)
Expand Down
2 changes: 1 addition & 1 deletion test/client-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('aborted response errors', (t) => {

client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.destroy()
body
.on('error', err => {
Expand Down
26 changes: 13 additions & 13 deletions test/client-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('GET errors and reconnect with pipelining 1', (t) => {
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -101,7 +101,7 @@ test('GET errors and reconnect with pipelining 3', (t) => {
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -171,7 +171,7 @@ function errorAndPipelining (type) {
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -241,7 +241,7 @@ function errorAndChunkedEncodingPipelining (type) {
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
const stream = body.readableNodeStream()
const stream = body.stream
stream.on('data', (buf) => {
bufs.push(buf)
})
Expand Down Expand Up @@ -708,7 +708,7 @@ test('GET errors body', (t) => {

client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
const stream = body.readableNodeStream()
const stream = body.stream
stream.resume()
stream.on('error', err => (
t.ok(err)
Expand Down Expand Up @@ -759,7 +759,7 @@ test('validate request body', (t) => {
body: ''
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
})

client.request({
Expand All @@ -768,7 +768,7 @@ test('validate request body', (t) => {
body: new Uint8Array()
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
})

client.request({
Expand All @@ -777,7 +777,7 @@ test('validate request body', (t) => {
body: Buffer.alloc(10)
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
})
})
})
Expand Down Expand Up @@ -908,7 +908,7 @@ test('queued request should not fail on socket destroy', (t) => {
method: 'GET'
}, (err, data) => {
t.error(err)
data.body.resume().on('error', () => {
data.body.stream.resume().on('error', () => {
t.pass()
})
client[kSocket].destroy()
Expand All @@ -917,7 +917,7 @@ test('queued request should not fail on socket destroy', (t) => {
method: 'GET'
}, (err, data) => {
t.error(err)
data.body.resume().on('end', () => {
data.body.stream.resume().on('end', () => {
t.pass()
})
})
Expand Down Expand Up @@ -946,7 +946,7 @@ test('queued request should fail on client destroy', (t) => {
method: 'GET'
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
.on('error', () => {
t.pass()
})
Expand Down Expand Up @@ -998,14 +998,14 @@ test('retry idempotent inflight', (t) => {
method: 'GET'
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
})
client.request({
path: '/',
method: 'GET'
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/client-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ test('pipeline abort duplex', (t) => {
method: 'PUT'
}, (err, data) => {
t.error(err)
data.body.resume()
data.body.stream.resume()

client.pipeline({
path: '/',
Expand Down
27 changes: 14 additions & 13 deletions test/client-pipelining.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,17 @@ test('pipeline 1 is 1 active request', (t) => {
method: 'GET'
}, (err, data) => {
t.error(err)
finished(data.body, (err) => {
const stream = data.body.stream
finished(stream, (err) => {
t.ok(err)
client.close((err) => {
t.error(err)
})
})
data.body.destroy()
stream.destroy()
res2.end()
}))
data.body.resume()
data.body.stream.resume()
res2.end()
})
t.ok(client[kSize] <= client.pipelining)
Expand Down Expand Up @@ -194,7 +195,7 @@ test('pipelined chunked POST stream', (t) => {
path: '/',
method: 'GET'
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

Expand All @@ -207,15 +208,15 @@ test('pipelined chunked POST stream', (t) => {
}
})
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

client.request({
path: '/',
method: 'GET'
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

Expand All @@ -228,7 +229,7 @@ test('pipelined chunked POST stream', (t) => {
}
})
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})
})
Expand Down Expand Up @@ -261,7 +262,7 @@ test('pipelined chunked POST iterator', (t) => {
path: '/',
method: 'GET'
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

Expand All @@ -274,15 +275,15 @@ test('pipelined chunked POST iterator', (t) => {
}
})()
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

client.request({
path: '/',
method: 'GET'
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})

Expand All @@ -295,7 +296,7 @@ test('pipelined chunked POST iterator', (t) => {
}
})()
}, (err, { body }) => {
body.resume()
body.stream.resume()
t.error(err)
})
})
Expand Down Expand Up @@ -398,7 +399,7 @@ test('pipelining non-idempotent', (t) => {
}, (err, data) => {
t.error(err)
t.equal(ended, true)
data.body.resume()
data.body.stream.resume()
})
})
})
Expand Down Expand Up @@ -455,7 +456,7 @@ function pipeliningNonIdempotentWithBody (bodyType) {
}, (err, data) => {
t.error(err)
t.equal(ended, true)
data.body.resume()
data.body.stream.resume()
})
})
})
Expand Down
1 change: 1 addition & 0 deletions test/client-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('multiple reconnect', (t) => {
client.request({ path: '/', method: 'GET' }, (err, data) => {
t.error(err)
data.body
.stream
.resume()
.on('end', () => {
t.pass()
Expand Down
1 change: 1 addition & 0 deletions test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ test('trailers', (t) => {
})

body
.stream
.on('data', () => t.fail())
.on('end', () => {
t.strictSame(trailers, { 'content-md5': 'test' })
Expand Down
Loading

0 comments on commit 1865f18

Please sign in to comment.