Skip to content

Commit c6bcb5c

Browse files
committed
add unit test for max buffer
1 parent 6d46a1c commit c6bcb5c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test.js

+20
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ let httpHandler = (req, res) => {
7777
compressor.write('Hello there')
7878
compressor.end()
7979
break
80+
case '/large':
81+
res.writeHead(200, {
82+
'Content-Length': 5e4
83+
})
84+
res.end(Buffer.alloc(5e4))
85+
break
8086
default:
8187
res.writeHead(404)
8288
res.end('Not a valid test endpoint')
@@ -525,6 +531,20 @@ test('Parse empty JSON response', () => {
525531
})
526532
})
527533

534+
test('Maximum Buffer exceeded', () => {
535+
p({
536+
'url': 'http://localhost:5136/large',
537+
'method': 'GET',
538+
'timeout': 500,
539+
'maxBuffer': 5e2,
540+
}, (err, res) => {
541+
if (err && err.message === "Server aborted request") {
542+
return assert.ok(true, 'Request exceeding maximum Buffer size was aborted')
543+
}
544+
return assert.ok(false, 'Request exceeding maximum Buffer size was not aborted')
545+
})
546+
})
547+
528548
let httpServer = http.createServer(httpHandler).listen(5136, async ()=>{
529549
test.after(() => {
530550
setTimeout(()=>{

0 commit comments

Comments
 (0)