Skip to content

Commit

Permalink
fix: test for checking large response body
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm committed Nov 17, 2020
1 parent 4e8230d commit bea5a7b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/httpClient.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const os = require('os')
const http = require('http')
const path = require('path')
const test = require('tap').test
const Client = require('../lib/httpClient')
Expand Down Expand Up @@ -886,3 +887,36 @@ test('client invokes appropriate onResponse when using pipelining', (t) => {
}
})
})

test('client supports receiving large response body', (t) => {
t.plan(2)

const mockBody = Array.from({ length: 1024 * 10 }, (_, i) => `str-${i}`).join('\n')
const server = http.createServer((req, res) => {
res.end(mockBody)
})
server.listen(0)
server.unref()

let onResponseCalled = 0
const opts = server.address()
opts.method = 'POST'
opts.body = Buffer.from('hello world')
opts.requests = [
{
path: '/',
method: 'GET',
onResponse: (...args) => {
onResponseCalled++
}
}
]

const client = new Client(opts)

client.on('response', (statusCode, length) => {
t.equal(onResponseCalled, 1, 'onResponse should be called only once')
t.equal(statusCode, 200, 'status code matches')
client.destroy()
})
})

0 comments on commit bea5a7b

Please sign in to comment.