-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: update test-http-status-code to use countdown #17477
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,15 @@ | |
require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const Countdown = require('../common/countdown'); | ||
|
||
// Simple test of Node's HTTP ServerResponse.statusCode | ||
// ServerResponse.prototype.statusCode | ||
|
||
let testsComplete = 0; | ||
const tests = [200, 202, 300, 404, 451, 500]; | ||
let testIdx = 0; | ||
const countdown = new Countdown(tests.length, () => s.close()); | ||
|
||
const s = http.createServer(function(req, res) { | ||
const t = tests[testIdx]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed and then the |
||
|
@@ -43,9 +45,6 @@ s.listen(0, nextTest); | |
|
||
|
||
function nextTest() { | ||
if (testIdx + 1 === tests.length) { | ||
return s.close(); | ||
} | ||
const test = tests[testIdx]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just do |
||
|
||
http.get({ port: s.address().port }, function(response) { | ||
|
@@ -55,13 +54,14 @@ function nextTest() { | |
response.on('end', function() { | ||
testsComplete++; | ||
testIdx += 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These variable additions would both be removed. |
||
nextTest(); | ||
if (countdown.dec()) | ||
nextTest(); | ||
}); | ||
response.resume(); | ||
}); | ||
} | ||
|
||
|
||
process.on('exit', function() { | ||
assert.strictEqual(5, testsComplete); | ||
assert.strictEqual(6, testsComplete); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code can actually be removed, as well as the |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testsComplete
andtestIdx
can be removed. Instead addlet test;
.