mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
This commit removes `common.crashOnUnhandledRejection()` and adds `common.disableCrashOnUnhandledRejection()`. To reduce the risk of mistakes and make writing tests that involve promises simpler, always install the unhandledRejection hook in tests and provide a way to disable it for the rare cases where it's needed. PR-URL: https://github.com/nodejs/node/pull/21849 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// Verifies that a full HTTP2 pipeline handles backpressure.
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
const makeDuplexPair = require('../common/duplexpair');
|
|
|
|
{
|
|
let req;
|
|
const server = http2.createServer();
|
|
server.on('stream', common.mustCallAsync(async (stream, headers) => {
|
|
stream.respond({
|
|
'content-type': 'text/html',
|
|
':status': 200
|
|
});
|
|
req._readableState.highWaterMark = 20;
|
|
stream._writableState.highWaterMark = 20;
|
|
assert.strictEqual(stream.write('A'.repeat(5)), true);
|
|
assert.strictEqual(stream.write('A'.repeat(40)), false);
|
|
assert.strictEqual(await event(req, 'data'), 'A'.repeat(5));
|
|
assert.strictEqual(await event(req, 'data'), 'A'.repeat(40));
|
|
await event(stream, 'drain');
|
|
assert.strictEqual(stream.write('A'.repeat(5)), true);
|
|
assert.strictEqual(stream.write('A'.repeat(40)), false);
|
|
}));
|
|
|
|
const { clientSide, serverSide } = makeDuplexPair();
|
|
server.emit('connection', serverSide);
|
|
|
|
const client = http2.connect('http://localhost:80', {
|
|
createConnection: common.mustCall(() => clientSide)
|
|
});
|
|
|
|
req = client.request({ ':path': '/' });
|
|
req.setEncoding('utf8');
|
|
req.end();
|
|
}
|
|
|
|
function event(ee, eventName) {
|
|
return new Promise((resolve) => {
|
|
ee.once(eventName, common.mustCall(resolve));
|
|
});
|
|
}
|