Skip to content

Commit 99e6607

Browse files
trevnorrisrvagg
authored andcommittedOct 2, 2015
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: #3139 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-by: Stephen Belanger <[email protected]>
1 parent e561585 commit 99e6607

File tree

5 files changed

+106
-6
lines changed

5 files changed

+106
-6
lines changed
 

Diff for: ‎src/async-wrap.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ namespace node {
1212

1313
#define NODE_ASYNC_PROVIDER_TYPES(V) \
1414
V(NONE) \
15-
V(CARES) \
16-
V(CONNECTWRAP) \
1715
V(CRYPTO) \
1816
V(FSEVENTWRAP) \
1917
V(FSREQWRAP) \
2018
V(GETADDRINFOREQWRAP) \
2119
V(GETNAMEINFOREQWRAP) \
2220
V(JSSTREAM) \
2321
V(PIPEWRAP) \
22+
V(PIPECONNECTWRAP) \
2423
V(PROCESSWRAP) \
2524
V(QUERYWRAP) \
26-
V(REQWRAP) \
2725
V(SHUTDOWNWRAP) \
2826
V(SIGNALWRAP) \
2927
V(STATWATCHER) \
3028
V(TCPWRAP) \
29+
V(TCPCONNECTWRAP) \
3130
V(TIMERWRAP) \
3231
V(TLSWRAP) \
3332
V(TTYWRAP) \
3433
V(UDPWRAP) \
34+
V(UDPSENDWRAP) \
3535
V(WRITEWRAP) \
3636
V(ZLIB)
3737

Diff for: ‎src/pipe_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PipeConnectWrap : public ReqWrap<uv_connect_t> {
4242

4343

4444
PipeConnectWrap::PipeConnectWrap(Environment* env, Local<Object> req_wrap_obj)
45-
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPEWRAP) {
45+
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP) {
4646
Wrap(req_wrap_obj, this);
4747
}
4848

Diff for: ‎src/tcp_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TCPConnectWrap : public ReqWrap<uv_connect_t> {
4141

4242

4343
TCPConnectWrap::TCPConnectWrap(Environment* env, Local<Object> req_wrap_obj)
44-
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPWRAP) {
44+
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP) {
4545
Wrap(req_wrap_obj, this);
4646
}
4747

Diff for: ‎src/udp_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SendWrap : public ReqWrap<uv_udp_send_t> {
4444
SendWrap::SendWrap(Environment* env,
4545
Local<Object> req_wrap_obj,
4646
bool have_callback)
47-
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_UDPWRAP),
47+
: ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_UDPSENDWRAP),
4848
have_callback_(have_callback) {
4949
Wrap(req_wrap_obj, this);
5050
}

Diff for: ‎test/parallel/test-async-wrap-check-providers.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const crypto = require('crypto');
6+
const dgram = require('dgram');
7+
const dns = require('dns');
8+
const fs = require('fs');
9+
const net = require('net');
10+
const tls = require('tls');
11+
const zlib = require('zlib');
12+
const ChildProcess = require('child_process').ChildProcess;
13+
const StreamWrap = require('_stream_wrap').StreamWrap;
14+
const async_wrap = process.binding('async_wrap');
15+
const pkeys = Object.keys(async_wrap.Providers);
16+
17+
let keyList = pkeys.slice();
18+
// Drop NONE
19+
keyList.splice(0, 1);
20+
21+
22+
function init(id) {
23+
keyList = keyList.filter(e => e != pkeys[id]);
24+
}
25+
26+
function noop() { }
27+
28+
async_wrap.setupHooks(init, noop, noop);
29+
30+
async_wrap.enable();
31+
32+
33+
setTimeout(function() { });
34+
35+
fs.stat(__filename, noop);
36+
fs.watchFile(__filename, noop);
37+
fs.unwatchFile(__filename);
38+
fs.watch(__filename).close();
39+
40+
dns.lookup('localhost', noop);
41+
dns.lookupService('::', 0, noop);
42+
dns.resolve('localhost', noop);
43+
44+
new StreamWrap(new net.Socket());
45+
46+
new (process.binding('tty_wrap').TTY)();
47+
48+
crypto.randomBytes(1, noop);
49+
50+
try {
51+
fs.unlinkSync(common.PIPE);
52+
} catch(e) { }
53+
54+
net.createServer(function(c) {
55+
c.end();
56+
this.close();
57+
}).listen(common.PIPE, function() {
58+
net.connect(common.PIPE, noop);
59+
});
60+
61+
net.createServer(function(c) {
62+
c.end();
63+
this.close(checkTLS);
64+
}).listen(common.PORT, function() {
65+
net.connect(common.PORT, noop);
66+
});
67+
68+
dgram.createSocket('udp4').bind(common.PORT, function() {
69+
this.send(new Buffer(2), 0, 2, common.PORT, '::', () => {
70+
this.close();
71+
});
72+
});
73+
74+
process.on('SIGINT', () => process.exit());
75+
76+
// Run from closed net server above.
77+
function checkTLS() {
78+
let options = {
79+
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
80+
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
81+
};
82+
let server = tls.createServer(options, noop).listen(common.PORT, function() {
83+
tls.connect(common.PORT, { rejectUnauthorized: false }, function() {
84+
this.destroy();
85+
server.close();
86+
});
87+
});
88+
}
89+
90+
zlib.createGzip();
91+
92+
new ChildProcess();
93+
94+
process.on('exit', function() {
95+
if (keyList.length !== 0) {
96+
process._rawDebug('Not all keys have been used:');
97+
process._rawDebug(keyList);
98+
assert.equal(keyList.length, 0);
99+
}
100+
});

0 commit comments

Comments
 (0)
Please sign in to comment.