mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
4f2e372716
Export a new common.noop no-operation function for general use. Allow using common.mustCall() without a fn argument to simplify test cases. Replace various non-op functions throughout tests with common.noop PR-URL: https://github.com/nodejs/node/pull/12027 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
const async_wrap = process.binding('async_wrap');
|
|
const providers = Object.keys(async_wrap.Providers);
|
|
|
|
const uidSymbol = Symbol('uid');
|
|
|
|
let cntr = 0;
|
|
let client;
|
|
|
|
function init(uid, type, parentUid, parentHandle) {
|
|
this[uidSymbol] = uid;
|
|
|
|
if (parentHandle) {
|
|
cntr++;
|
|
// Cannot assert in init callback or will abort.
|
|
process.nextTick(() => {
|
|
assert.strictEqual(providers[type], 'TCPWRAP');
|
|
assert.strictEqual(parentUid, server._handle[uidSymbol],
|
|
'server uid doesn\'t match parent uid');
|
|
assert.strictEqual(parentHandle, server._handle,
|
|
'server handle doesn\'t match parent handle');
|
|
assert.strictEqual(this, client._handle, 'client doesn\'t match context');
|
|
});
|
|
}
|
|
}
|
|
|
|
async_wrap.setupHooks({ init });
|
|
async_wrap.enable();
|
|
|
|
const server = net.createServer(function(c) {
|
|
client = c;
|
|
// Allow init callback to run before closing.
|
|
setImmediate(() => {
|
|
c.end();
|
|
this.close();
|
|
});
|
|
}).listen(0, function() {
|
|
net.connect(this.address().port, common.noop);
|
|
});
|
|
|
|
|
|
process.on('exit', function() {
|
|
// init should have only been called once with a parent.
|
|
assert.strictEqual(cntr, 1);
|
|
});
|