Skip to content

Commit 99e6607

Browse files
trevnorrisrvagg
authored andcommitted
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 <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Stephen Belanger <admin@stephenbelanger.com>
1 parent e561585 commit 99e6607

5 files changed

Lines changed: 106 additions & 6 deletions

File tree

‎src/async-wrap.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ namespace node {
1212

1313
#defineNODE_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

‎src/pipe_wrap.cc‎

Lines changed: 1 addition & 1 deletion
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

‎src/tcp_wrap.cc‎

Lines changed: 1 addition & 1 deletion
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

‎src/udp_wrap.cc‎

Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constcrypto=require('crypto');
6+
constdgram=require('dgram');
7+
constdns=require('dns');
8+
constfs=require('fs');
9+
constnet=require('net');
10+
consttls=require('tls');
11+
constzlib=require('zlib');
12+
constChildProcess=require('child_process').ChildProcess;
13+
constStreamWrap=require('_stream_wrap').StreamWrap;
14+
constasync_wrap=process.binding('async_wrap');
15+
constpkeys=Object.keys(async_wrap.Providers);
16+
17+
letkeyList=pkeys.slice();
18+
// Drop NONE
19+
keyList.splice(0,1);
20+
21+
22+
functioninit(id){
23+
keyList=keyList.filter(e=>e!=pkeys[id]);
24+
}
25+
26+
functionnoop(){}
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+
newStreamWrap(newnet.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(newBuffer(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+
functioncheckTLS(){
78+
letoptions={
79+
key: fs.readFileSync(common.fixturesDir+'/keys/ec-key.pem'),
80+
cert: fs.readFileSync(common.fixturesDir+'/keys/ec-cert.pem')
81+
};
82+
letserver=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+
newChildProcess();
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)