From e52864b4b8b05fb91b77f22d24a8a4a05c6f43a0 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Tue, 29 Sep 2015 15:20:41 -0600 Subject: [PATCH] async_wrap: update providers and add test Several provider ids have been removed that are no longer in use. Others have been updated to match their class constructors. Add test to ensure all internally listed providers are used. PR-URL: https://github.com/nodejs/node/pull/3139 Reviewed-By: Fedor Indutny Reviewed-By: Ben Noordhuis Reviewed-by: Stephen Belanger --- src/async-wrap.h | 6 +- src/pipe_wrap.cc | 2 +- src/tcp_wrap.cc | 2 +- src/udp_wrap.cc | 2 +- .../test-async-wrap-check-providers.js | 100 ++++++++++++++++++ 5 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-async-wrap-check-providers.js diff --git a/src/async-wrap.h b/src/async-wrap.h index d292bb4774f054..3999607bb293c2 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -12,8 +12,6 @@ namespace node { #define NODE_ASYNC_PROVIDER_TYPES(V) \ V(NONE) \ - V(CARES) \ - V(CONNECTWRAP) \ V(CRYPTO) \ V(FSEVENTWRAP) \ V(FSREQWRAP) \ @@ -21,17 +19,19 @@ namespace node { V(GETNAMEINFOREQWRAP) \ V(JSSTREAM) \ V(PIPEWRAP) \ + V(PIPECONNECTWRAP) \ V(PROCESSWRAP) \ V(QUERYWRAP) \ - V(REQWRAP) \ V(SHUTDOWNWRAP) \ V(SIGNALWRAP) \ V(STATWATCHER) \ V(TCPWRAP) \ + V(TCPCONNECTWRAP) \ V(TIMERWRAP) \ V(TLSWRAP) \ V(TTYWRAP) \ V(UDPWRAP) \ + V(UDPSENDWRAP) \ V(WRITEWRAP) \ V(ZLIB) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 62bfe0a92e672c..84164723e95b99 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -42,7 +42,7 @@ class PipeConnectWrap : public ReqWrap { PipeConnectWrap::PipeConnectWrap(Environment* env, Local req_wrap_obj) - : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPEWRAP) { + : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP) { Wrap(req_wrap_obj, this); } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 9bdf8ccc1d4a00..3f3e6a0ad4a752 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -41,7 +41,7 @@ class TCPConnectWrap : public ReqWrap { TCPConnectWrap::TCPConnectWrap(Environment* env, Local req_wrap_obj) - : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPWRAP) { + : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP) { Wrap(req_wrap_obj, this); } diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index dff2235f9f5ad0..cb678f14fb3826 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -44,7 +44,7 @@ class SendWrap : public ReqWrap { SendWrap::SendWrap(Environment* env, Local req_wrap_obj, bool have_callback) - : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_UDPWRAP), + : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_UDPSENDWRAP), have_callback_(have_callback) { Wrap(req_wrap_obj, this); } diff --git a/test/parallel/test-async-wrap-check-providers.js b/test/parallel/test-async-wrap-check-providers.js new file mode 100644 index 00000000000000..bec8768e923925 --- /dev/null +++ b/test/parallel/test-async-wrap-check-providers.js @@ -0,0 +1,100 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const crypto = require('crypto'); +const dgram = require('dgram'); +const dns = require('dns'); +const fs = require('fs'); +const net = require('net'); +const tls = require('tls'); +const zlib = require('zlib'); +const ChildProcess = require('child_process').ChildProcess; +const StreamWrap = require('_stream_wrap').StreamWrap; +const async_wrap = process.binding('async_wrap'); +const pkeys = Object.keys(async_wrap.Providers); + +let keyList = pkeys.slice(); +// Drop NONE +keyList.splice(0, 1); + + +function init(id) { + keyList = keyList.filter(e => e != pkeys[id]); +} + +function noop() { } + +async_wrap.setupHooks(init, noop, noop); + +async_wrap.enable(); + + +setTimeout(function() { }); + +fs.stat(__filename, noop); +fs.watchFile(__filename, noop); +fs.unwatchFile(__filename); +fs.watch(__filename).close(); + +dns.lookup('localhost', noop); +dns.lookupService('::', 0, noop); +dns.resolve('localhost', noop); + +new StreamWrap(new net.Socket()); + +new (process.binding('tty_wrap').TTY)(); + +crypto.randomBytes(1, noop); + +try { + fs.unlinkSync(common.PIPE); +} catch(e) { } + +net.createServer(function(c) { + c.end(); + this.close(); +}).listen(common.PIPE, function() { + net.connect(common.PIPE, noop); +}); + +net.createServer(function(c) { + c.end(); + this.close(checkTLS); +}).listen(common.PORT, function() { + net.connect(common.PORT, noop); +}); + +dgram.createSocket('udp4').bind(common.PORT, function() { + this.send(new Buffer(2), 0, 2, common.PORT, '::', () => { + this.close(); + }); +}); + +process.on('SIGINT', () => process.exit()); + +// Run from closed net server above. +function checkTLS() { + let options = { + key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem') + }; + let server = tls.createServer(options, noop).listen(common.PORT, function() { + tls.connect(common.PORT, { rejectUnauthorized: false }, function() { + this.destroy(); + server.close(); + }); + }); +} + +zlib.createGzip(); + +new ChildProcess(); + +process.on('exit', function() { + if (keyList.length !== 0) { + process._rawDebug('Not all keys have been used:'); + process._rawDebug(keyList); + assert.equal(keyList.length, 0); + } +});