fix: allow ClientRequest responses to be throttled (#25531)

* fix: allow net streams to be throttled [WIP]

* fix: handle resume throttling within IncomingMessage [WIP]

* fix: fix urlLoader typing, add throttle test

* fix: fix lint and increase test timeout for Linux

* fix: increase test chunk limit to 20 and timeout to 2000

Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
This commit is contained in:
Keeley Hammond 2020-10-05 17:47:41 -07:00 committed by GitHub
parent 53ee708fe8
commit 6356cd4018
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 8 deletions

View file

@ -4,7 +4,7 @@ import * as http from 'http';
import * as url from 'url';
import { AddressInfo, Socket } from 'net';
import { emittedOnce } from './events-helpers';
import { defer } from './spec-helpers';
import { defer, delay } from './spec-helpers';
const kOneKiloByte = 1024;
const kOneMegaByte = kOneKiloByte * kOneKiloByte;
@ -1476,6 +1476,28 @@ describe('net module', () => {
await collectStreamBody(nodeResponse);
expect(nodeRequestProcessed).to.equal(true);
});
it('should correctly throttle an incoming stream', async () => {
let numChunksSent = 0;
const serverUrl = await respondOnce.toSingleURL((request, response) => {
const data = randomString(kOneMegaByte);
const write = () => {
let ok = true;
do {
numChunksSent++;
if (numChunksSent > 30) return;
ok = response.write(data);
} while (ok);
response.once('drain', write);
};
write();
});
const urlRequest = net.request(serverUrl);
urlRequest.on('response', () => {});
urlRequest.end();
await delay(2000);
expect(numChunksSent).to.be.at.most(20);
});
});
describe('Stability and performance', () => {