Skip to content
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-timeout-overflow to use common.mustCall #17528

Closed
wants to merge 2 commits into from
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
22 changes: 13 additions & 9 deletions test/parallel/test-http-timeout-overflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@

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

const http = require('http');
let response;

let serverRequests = 0;
let clientRequests = 0;
const serverReqCountdown = new Countdown(1, () => {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('OK');
});

const server = http.createServer(function(req, res) {
Copy link
Member

Choose a reason for hiding this comment

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

This could be common.mustCall(function(req, res) { /* function body */ }) which would then confirm that it executes during the duration of the test. Then no Countdown is needed.

Copy link
Contributor Author

@collin5 collin5 Dec 8, 2017

Choose a reason for hiding this comment

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

@apapirovski Right, that actually makes more sense. Let me do it ASAP 👍

serverRequests++;
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('OK');
response = res;
serverReqCountdown.dec();
});

const clientReqCountdown = new Countdown(1, () => server.close());

server.listen(0, function() {
function callback() {}

Expand All @@ -45,8 +50,7 @@ server.listen(0, function() {
req.clearTimeout(callback);

res.on('end', function() {
Copy link
Member

Choose a reason for hiding this comment

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

This can also use common.mustCall so common.mustCall(function() { /* function body */ }).

clientRequests++;
server.close();
clientReqCountdown.dec();
});

res.resume();
Expand All @@ -58,6 +62,6 @@ server.listen(0, function() {
});

process.once('exit', function() {
assert.strictEqual(clientRequests, 1);
assert.strictEqual(serverRequests, 1);
assert.strictEqual(clientReqCountdown.remaining, 0);
assert.strictEqual(serverReqCountdown.remaining, 0);
});