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

Converting test to use Countdown #17505

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion test/parallel/test-http-expect-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ function nextTest() {

process.on('exit', function() {
assert.strictEqual(2, testsComplete);
});
});
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be an unrelated change. The newline should remain.

2 changes: 1 addition & 1 deletion test/parallel/test-http-keepalive-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ function makeRequest(n) {
process.on('exit', function() {
assert.strictEqual(actualRequests, expectRequests);
console.log('ok');
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Same here. Unrelated change, newline should remain.

11 changes: 7 additions & 4 deletions test/parallel/test-http-should-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ require('../common');
const assert = require('assert');
const http = require('http');
const net = require('net');
const common = require('../common');
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be the first include within the file. Could you update?

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

const SERVER_RESPONSES = [
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n',
Expand All @@ -45,6 +47,8 @@ let requests = 0;
let responses = 0;
http.globalAgent.maxSockets = 5;

const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please remove the space between length and the comma?


const server = net.createServer(function(socket) {
socket.write(SERVER_RESPONSES[requests]);
++requests;
Expand All @@ -56,18 +60,17 @@ const server = net.createServer(function(socket) {
`${SERVER_RESPONSES[responses]} should ${
SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`);
++responses;
if (responses < SHOULD_KEEP_ALIVE.length) {
countdown.dec();
if (countdown.remaining) {
makeRequest();
} else {
server.close();
}
res.resume();
});
}

makeRequest();
});


Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change, please remove.

process.on('exit', function() {
assert.strictEqual(requests, SERVER_RESPONSES.length);
assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length);
Copy link
Member

Choose a reason for hiding this comment

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

This whole process.on('exit') block shouldn't be necessary if we're trying to use Countdown.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, Thanks for the quick response,
I will be happy if you can clarify some things:

  1. i kept the "requests" and the "responses" variables because they are used on SERVER_RESPONSES[requests] under the makeRequest function.
    since those variables are used inside of an Array if we use countdown we will get another value from the array SERVER_RESPONSES.
    can you be more clear about your solution with the shift() ?

  2. should I make another countdown instance for requests as well?

Copy link
Member

Choose a reason for hiding this comment

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

There are two directions this can go in.

  1. Instead of using requests and responses, just use SERVER_RESPONSES.length - countdown.remaining — that will get you the same index.
  2. shift removes and returns the element within an array that's at index 0. You can use this to store the current value from SERVER_RESPONSES and SHOULD_KEEP_ALIVE.

Expand Down