Skip to content

Commit 6da49ac

Browse files
TrottFishrock123
authored andcommitted
test: handle SmartOS bug in test-tls-session-cache
Sometimes, a SmartOS bug results in ECONNREFUSED when trying to connect to the TLS server that the test starts. Retry in that situation. Fixes: #5111 Refs: https://smartos.org/bugview/OS-2767 PR-URL: #7505 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 9b5be44 commit 6da49ac

1 file changed

Lines changed: 41 additions & 27 deletions

File tree

‎test/parallel/test-tls-session-cache.js‎

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
varcommon=require('../common');
2+
constcommon=require('../common');
33

44
if(!common.opensslCli){
55
common.skip('node compiled without OpenSSL CLI.');
@@ -18,17 +18,17 @@ doTest({ tickets: false }, function() {
1818
});
1919

2020
functiondoTest(testOptions,callback){
21-
varassert=require('assert');
22-
vartls=require('tls');
23-
varfs=require('fs');
24-
varjoin=require('path').join;
25-
varspawn=require('child_process').spawn;
21+
constassert=require('assert');
22+
consttls=require('tls');
23+
constfs=require('fs');
24+
constjoin=require('path').join;
25+
constspawn=require('child_process').spawn;
2626

27-
varkeyFile=join(common.fixturesDir,'agent.key');
28-
varcertFile=join(common.fixturesDir,'agent.crt');
29-
varkey=fs.readFileSync(keyFile);
30-
varcert=fs.readFileSync(certFile);
31-
varoptions={
27+
constkeyFile=join(common.fixturesDir,'agent.key');
28+
constcertFile=join(common.fixturesDir,'agent.crt');
29+
constkey=fs.readFileSync(keyFile);
30+
constcert=fs.readFileSync(certFile);
31+
constoptions={
3232
key: key,
3333
cert: cert,
3434
ca: [cert],
@@ -38,7 +38,7 @@ function doTest(testOptions, callback) {
3838
varresumeCount=0;
3939
varsession;
4040

41-
varserver=tls.createServer(options,function(cleartext){
41+
constserver=tls.createServer(options,function(cleartext){
4242
cleartext.on('error',function(er){
4343
// We're ok with getting ECONNRESET in this test, but it's
4444
// timing-dependent, and thus unreliable. Any other errors
@@ -72,7 +72,7 @@ function doTest(testOptions, callback) {
7272
});
7373

7474
server.listen(0,function(){
75-
varargs=[
75+
constargs=[
7676
's_client',
7777
'-tls1',
7878
'-connect',`localhost:${this.address().port}`,
@@ -86,21 +86,35 @@ function doTest(testOptions, callback) {
8686
if(common.isWindows)
8787
args.push('-no_rand_screen');
8888

89-
varclient=spawn(common.opensslCli,args,{
90-
stdio: [0,1,'pipe']
91-
});
92-
varerr='';
93-
client.stderr.setEncoding('utf8');
94-
client.stderr.on('data',function(chunk){
95-
err+=chunk;
96-
});
97-
client.on('exit',function(code){
98-
console.error('done');
99-
assert.equal(code,0);
100-
server.close(function(){
101-
setTimeout(callback,100);
89+
functionspawnClient(){
90+
constclient=spawn(common.opensslCli,args,{
91+
stdio: [0,1,'pipe']
10292
});
103-
});
93+
varerr='';
94+
client.stderr.setEncoding('utf8');
95+
client.stderr.on('data',function(chunk){
96+
err+=chunk;
97+
});
98+
99+
client.on('exit',common.mustCall(function(code,signal){
100+
if(code!==0){
101+
// If SmartOS and connection refused, then retry. See
102+
// https://github.com/nodejs/node/issues/2663.
103+
if(common.isSunOS&&err.includes('Connection refused')){
104+
requestCount=0;
105+
spawnClient();
106+
return;
107+
}
108+
common.fail(`code: ${code}, signal: ${signal}, output: ${err}`);
109+
}
110+
assert.equal(code,0);
111+
server.close(common.mustCall(function(){
112+
setTimeout(callback,100);
113+
}));
114+
}));
115+
}
116+
117+
spawnClient();
104118
});
105119

106120
process.on('exit',function(){

0 commit comments

Comments
 (0)