Skip to content
Closed
Changes from all 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
test: use Countdown instead of testsComplete
  • Loading branch information
Leko committed Dec 8, 2017
commit 4d13b8b0e06f64f3f99227f81d91ca8dc65bf87f
12 changes: 4 additions & 8 deletions test/parallel/test-http-response-status-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

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

let testsComplete = 0;

const testCases = [
{ path: '/200', statusMessage: 'OK',
response: 'HTTP/1.1 200 OK\r\n\r\n' },
Expand All @@ -49,6 +48,7 @@ testCases.findByPath = function(path) {
return matching[0];
};

const countdown = new Countdown(testCases.length, common.mustCall(() => {}));
const server = net.createServer(function(connection) {
connection.on('data', function(data) {
const path = data.toString().match(/GET (.*) HTTP\/1\.1/)[1];
Expand All @@ -71,7 +71,7 @@ function runTest(testCaseIndex) {
assert.strictEqual(testCase.statusMessage, response.statusMessage);

response.on('end', function() {
testsComplete++;
countdown.dec();

if (testCaseIndex + 1 < testCases.length) {
runTest(testCaseIndex + 1);
Expand All @@ -85,7 +85,3 @@ function runTest(testCaseIndex) {
}

server.listen(0, function() { runTest(0); });

process.on('exit', function() {
assert.strictEqual(testCases.length, testsComplete);
});