Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
https: made some improvements to test-https-agent.js
This is my first good contribution, on line 40 replaced '==' with '===' for a strict compare, on line 52 I replaces 'assert.equal' with 'assert.strictEqual' again for a strict compare.

Added some comments to make it clear what the test is doing and changed 'var' to 'const' where possible.
  • Loading branch information
Williams-Dan committed Sep 13, 2016
commit 7fe1e2c1b160f5714d372938ea8ea28fef05d9eb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ipch/
*.VC.opendb
.vs/
.vscode/
.idea/

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.

Please don't change .gitignore. There is another PR specifically for this and it is still being discussed.

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.

If you need .idea/ in your .gitignore, consider adding it to a personal global .gitignore file instead. https://help.github.com/articles/ignoring-files/#create-a-global-gitignore


/config.mk
/config.gypi
Expand Down
35 changes: 24 additions & 11 deletions test/parallel/test-https-agent.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
'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 = {
//Gets SSL Certificate and SSL Key.

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 think we can avoid this comment.

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) {
//Starts up a https server using the SSL Certificate and Key.

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.

Ditto.

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;

/*
the part being tested, Loops around 4 times on N,

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 also remove this, the following code is clear enough.

Each time it loops around another 4 times on M,
each time sending a https GET request for route '/'
each inner loop records the number of responses
and closes the https server once the https request has been send 16 times.
*/

server.listen(0, function() {
for (var i = 0; i < N; i++) {
Expand All @@ -37,7 +46,7 @@ server.listen(0, function() {
}, function(res) {
res.resume();
console.log(res.statusCode);

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.

What about replacing this line with assert.strictEqual(res.statusCode, 200);?

if (++responses == N * M) server.close();
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);

@lpinca lpinca Sep 14, 2016 •

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 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 @@ -47,7 +56,11 @@ server.listen(0, function() {
}
});

/*
Asserts the number of responses match the number of loops,

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.

Same thing here, I don't think the comment is necessary.

making sure all responses were sent successfully.
*/

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