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: https://github.com/nodejs/node/issues/5111 Refs: https://smartos.org/bugview/OS-2767 PR-URL: https://github.com/nodejs/node/pull/7505 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
7cbbec516d
commit
fb4c022fbe
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
if (!common.opensslCli) {
|
if (!common.opensslCli) {
|
||||||
common.skip('node compiled without OpenSSL CLI.');
|
common.skip('node compiled without OpenSSL CLI.');
|
||||||
@ -18,17 +18,17 @@ doTest({ tickets: false }, function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function doTest(testOptions, callback) {
|
function doTest(testOptions, callback) {
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var tls = require('tls');
|
const tls = require('tls');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var join = require('path').join;
|
const join = require('path').join;
|
||||||
var spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
var keyFile = join(common.fixturesDir, 'agent.key');
|
const keyFile = join(common.fixturesDir, 'agent.key');
|
||||||
var certFile = join(common.fixturesDir, 'agent.crt');
|
const certFile = join(common.fixturesDir, 'agent.crt');
|
||||||
var key = fs.readFileSync(keyFile);
|
const key = fs.readFileSync(keyFile);
|
||||||
var cert = fs.readFileSync(certFile);
|
const cert = fs.readFileSync(certFile);
|
||||||
var options = {
|
const options = {
|
||||||
key: key,
|
key: key,
|
||||||
cert: cert,
|
cert: cert,
|
||||||
ca: [cert],
|
ca: [cert],
|
||||||
@ -38,7 +38,7 @@ function doTest(testOptions, callback) {
|
|||||||
var resumeCount = 0;
|
var resumeCount = 0;
|
||||||
var session;
|
var session;
|
||||||
|
|
||||||
var server = tls.createServer(options, function(cleartext) {
|
const server = tls.createServer(options, function(cleartext) {
|
||||||
cleartext.on('error', function(er) {
|
cleartext.on('error', function(er) {
|
||||||
// We're ok with getting ECONNRESET in this test, but it's
|
// We're ok with getting ECONNRESET in this test, but it's
|
||||||
// timing-dependent, and thus unreliable. Any other errors
|
// timing-dependent, and thus unreliable. Any other errors
|
||||||
@ -72,7 +72,7 @@ function doTest(testOptions, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.listen(0, function() {
|
server.listen(0, function() {
|
||||||
var args = [
|
const args = [
|
||||||
's_client',
|
's_client',
|
||||||
'-tls1',
|
'-tls1',
|
||||||
'-connect', `localhost:${this.address().port}`,
|
'-connect', `localhost:${this.address().port}`,
|
||||||
@ -86,7 +86,8 @@ function doTest(testOptions, callback) {
|
|||||||
if (common.isWindows)
|
if (common.isWindows)
|
||||||
args.push('-no_rand_screen');
|
args.push('-no_rand_screen');
|
||||||
|
|
||||||
var client = spawn(common.opensslCli, args, {
|
function spawnClient() {
|
||||||
|
const client = spawn(common.opensslCli, args, {
|
||||||
stdio: [ 0, 1, 'pipe' ]
|
stdio: [ 0, 1, 'pipe' ]
|
||||||
});
|
});
|
||||||
var err = '';
|
var err = '';
|
||||||
@ -94,13 +95,26 @@ function doTest(testOptions, callback) {
|
|||||||
client.stderr.on('data', function(chunk) {
|
client.stderr.on('data', function(chunk) {
|
||||||
err += chunk;
|
err += chunk;
|
||||||
});
|
});
|
||||||
client.on('exit', function(code) {
|
|
||||||
console.error('done');
|
client.on('exit', common.mustCall(function(code, signal) {
|
||||||
|
if (code !== 0) {
|
||||||
|
// If SmartOS and connection refused, then retry. See
|
||||||
|
// https://github.com/nodejs/node/issues/2663.
|
||||||
|
if (common.isSunOS && err.includes('Connection refused')) {
|
||||||
|
requestCount = 0;
|
||||||
|
spawnClient();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
common.fail(`code: ${code}, signal: ${signal}, output: ${err}`);
|
||||||
|
}
|
||||||
assert.equal(code, 0);
|
assert.equal(code, 0);
|
||||||
server.close(function() {
|
server.close(common.mustCall(function() {
|
||||||
setTimeout(callback, 100);
|
setTimeout(callback, 100);
|
||||||
});
|
}));
|
||||||
});
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
spawnClient();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user