1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
2
+ const common = require ( '../common' ) ;
3
3
4
4
if ( ! common . opensslCli ) {
5
5
common . skip ( 'node compiled without OpenSSL CLI.' ) ;
@@ -18,17 +18,17 @@ doTest({ tickets: false }, function() {
18
18
} ) ;
19
19
20
20
function doTest ( testOptions , callback ) {
21
- var assert = require ( 'assert' ) ;
22
- var tls = require ( 'tls' ) ;
23
- var fs = require ( 'fs' ) ;
24
- var join = require ( 'path' ) . join ;
25
- var spawn = require ( 'child_process' ) . spawn ;
21
+ const assert = require ( 'assert' ) ;
22
+ const tls = require ( 'tls' ) ;
23
+ const fs = require ( 'fs' ) ;
24
+ const join = require ( 'path' ) . join ;
25
+ const spawn = require ( 'child_process' ) . spawn ;
26
26
27
- var keyFile = join ( common . fixturesDir , 'agent.key' ) ;
28
- var certFile = join ( common . fixturesDir , 'agent.crt' ) ;
29
- var key = fs . readFileSync ( keyFile ) ;
30
- var cert = fs . readFileSync ( certFile ) ;
31
- var options = {
27
+ const keyFile = join ( common . fixturesDir , 'agent.key' ) ;
28
+ const certFile = join ( common . fixturesDir , 'agent.crt' ) ;
29
+ const key = fs . readFileSync ( keyFile ) ;
30
+ const cert = fs . readFileSync ( certFile ) ;
31
+ const options = {
32
32
key : key ,
33
33
cert : cert ,
34
34
ca : [ cert ] ,
@@ -38,7 +38,7 @@ function doTest(testOptions, callback) {
38
38
var resumeCount = 0 ;
39
39
var session ;
40
40
41
- var server = tls . createServer ( options , function ( cleartext ) {
41
+ const server = tls . createServer ( options , function ( cleartext ) {
42
42
cleartext . on ( 'error' , function ( er ) {
43
43
// We're ok with getting ECONNRESET in this test, but it's
44
44
// timing-dependent, and thus unreliable. Any other errors
@@ -72,7 +72,7 @@ function doTest(testOptions, callback) {
72
72
} ) ;
73
73
74
74
server . listen ( 0 , function ( ) {
75
- var args = [
75
+ const args = [
76
76
's_client' ,
77
77
'-tls1' ,
78
78
'-connect' , `localhost:${ this . address ( ) . port } ` ,
@@ -86,21 +86,35 @@ function doTest(testOptions, callback) {
86
86
if ( common . isWindows )
87
87
args . push ( '-no_rand_screen' ) ;
88
88
89
- var client = spawn ( common . opensslCli , args , {
90
- stdio : [ 0 , 1 , 'pipe' ]
91
- } ) ;
92
- var err = '' ;
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
+ function spawnClient ( ) {
90
+ const client = spawn ( common . opensslCli , args , {
91
+ stdio : [ 0 , 1 , 'pipe' ]
102
92
} ) ;
103
- } ) ;
93
+ var err = '' ;
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 ( ) ;
104
118
} ) ;
105
119
106
120
process . on ( 'exit' , function ( ) {
0 commit comments