Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions test/parallel/test-https-agent.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var https = require('https');
const https = require('https');

var fs = require('fs');
const fs = require('fs');

var options = {
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};


var server = https.Server(options, function(req, res) {
const server = https.Server(options, function(req, res) {
res.writeHead(200);
res.end('hello world\n');
});


var responses = 0;
var N = 4;
var M = 4;
const N = 4;
const M = 4;


server.listen(0, function() {
for (var i = 0; i < N; i++) {
Expand All @@ -36,8 +37,8 @@ server.listen(0, function() {
rejectUnauthorized: false
}, function(res) {
res.resume();
console.log(res.statusCode);
if (++responses == N * M) server.close();
assert.strictEqual(res.statusCode, 200);
if (++responses === N * M) server.close();
}).on('error', function(e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to on('error', common.fail) or on('error', function(e) { throw e; }); not sure what is the preferred way, looks like both are used in other tests.

console.log(e.message);
Copy link
Copy Markdown
Member

@lpinca lpinca Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to throw the error here instead of logging the error message. Maybe the whole error listener can be removed, an error is thrown if there isn't one.

process.exit(1);
Expand All @@ -49,5 +50,5 @@ server.listen(0, function() {


process.on('exit', function() {
assert.equal(N * M, responses);
assert.strictEqual(N * M, responses);
});