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
Prev Previous commit
squash! minor edits to comments
  • Loading branch information
Trott authored Jun 11, 2018
commit 2c5f0c05bbedbf6647c436a90aa25ee4b3c60997
12 changes: 6 additions & 6 deletions test/parallel/test-http-client-timeout-option-with-agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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.

Would you be willing to add a comment here explaining what this is testing?

const common = require('../common');

// This test ensure http request with timeout and agent,
// Test that when http request uses both timeout and agent,
// timeout will work as expected.

const assert = require('assert');
Expand All @@ -21,7 +21,7 @@ const options = {
};

const server = http.createServer(() => {
// never response
// Never respond.
});

server.listen(0, options.host, function() {
Expand All @@ -33,23 +33,23 @@ function doRequest() {
const req = http.request(options);
const start = Date.now();
req.on('error', () => {
// this space is intentionally left blank
// This space is intentionally left blank.
});
req.on('close', common.mustCall(() => server.close()));

let timeout_events = 0;
req.on('timeout', common.mustCall(() => {
timeout_events += 1;
const duration = Date.now() - start;
// The timeout event can not be accurately fired, It will delay
// in some milliseconds, so test it in second units.
// The timeout event cannot be precisely timed. It will delay
// some number of milliseconds, so test it in second units.
assert.strictEqual(duration / 1000 | 0, HTTP_CLIENT_TIMEOUT / 1000);
}));
req.end();

setTimeout(function() {
req.destroy();
assert.strictEqual(timeout_events, 1);
// Ensure the `timeout` be event fired only once.
// Ensure the `timeout` event fired only once.
}, common.platformTimeout(HTTP_CLIENT_TIMEOUT * 2));
}