0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-net-server-capture-rejection.js
Matteo Collina 8508edbf32 net: implement capture rejections for 'connection' event
PR-URL: https://github.com/nodejs/node/pull/27867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-12-03 12:14:52 +01:00

28 lines
598 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const events = require('events');
const { createServer, connect } = require('net');
events.captureRejections = true;
const server = createServer(common.mustCall(async (sock) => {
server.close();
const _err = new Error('kaboom');
sock.on('error', common.mustCall((err) => {
assert.strictEqual(err, _err);
}));
throw _err;
}));
server.listen(0, common.mustCall(() => {
const sock = connect(
server.address().port,
server.address().host
);
sock.on('close', common.mustCall());
}));