Skip to content
Closed
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
adding Countdown to test-http-set-cookies test
  • Loading branch information
shilomagen committed Dec 6, 2017
commit 3ef1c59cebc1c1697a1411ab5124db00d13ee22d
26 changes: 11 additions & 15 deletions test/parallel/test-http-set-cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

let nresponses = 0;

const countdown = new Countdown(2, common.mustCall(() => server.close()));
Copy link
Contributor

@apapirovski apapirovski Dec 6, 2017

Choose a reason for hiding this comment

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

This doesn't strictly need the common.mustCall but it's not a deal breaker. (If you do remove it, you'll need to also remove the const common = part above (but keep the actual require).

const server = http.createServer(function(req, res) {
if (req.url === '/one') {
res.writeHead(200, [['set-cookie', 'A'],
['content-type', 'text/plain']]);
['content-type', 'text/plain']]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you undo this change? It should stay lined up.

res.end('one\n');
} else {
res.writeHead(200, [['set-cookie', 'A'],
['set-cookie', 'B'],
['content-type', 'text/plain']]);
['set-cookie', 'B'],
['content-type', 'text/plain']]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for these two lines. They should be lined up as before.

res.end('two\n');
}
});
Expand All @@ -44,7 +44,7 @@ server.on('listening', function() {
//
// one set-cookie header
//
http.get({ port: this.address().port, path: '/one' }, function(res) {
http.get({port: this.address().port, path: '/one'}, function(res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the space to the left and right within the braces.

// set-cookie headers are always return in an array.
// even if there is only one.
assert.deepStrictEqual(['A'], res.headers['set-cookie']);
Expand All @@ -55,15 +55,13 @@ server.on('listening', function() {
});

res.on('end', function() {
if (++nresponses === 2) {
server.close();
}
countdown.dec();
});
});

// two set-cookie headers

http.get({ port: this.address().port, path: '/two' }, function(res) {
http.get({port: this.address().port, path: '/two'}, function(res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, please add the spaces back in.

assert.deepStrictEqual(['A', 'B'], res.headers['set-cookie']);
assert.strictEqual('text/plain', res.headers['content-type']);

Expand All @@ -72,14 +70,12 @@ server.on('listening', function() {
});

res.on('end', function() {
if (++nresponses === 2) {
server.close();
}
countdown.dec();
});
});

});

process.on('exit', function() {
assert.strictEqual(2, nresponses);
assert.strictEqual(countdown.remaining, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

The process.on('exit') can be removed as server.close() needs to run before the process will exit.

});