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: remove unnecessary .toString() calls in HTTP tests #43731

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion test/parallel/test-http-missing-header-separator-cr.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ server.listen(0, common.mustSucceed(() => {
let response = '';

client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

client.setEncoding('utf8');
Copy link
Member

Choose a reason for hiding this comment

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

Nit(feel free to ignore): would be better to move client.setEncoding('utf8'); before client.on('data'?

Reason:

  1. keep consistent with other use cases
  2. don't make us guess if client.setEncoding('utf8') after attach data listener would cause problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fwiw, my preferred way is client.setEncoding('utf8').on('data', ...') 😄

Ultimately, it doesn't matter. If we do clean this up, it might also be a good idea to do so across all tests for consistency.

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http-server-close-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ server.listen(0, function() {
const client2 = connect(port);
let response = '';

client2.setEncoding('utf8');

client2.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

if (response.endsWith('0\r\n\r\n')) {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http-server-close-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ server.listen(0, function() {
const client2 = connect(port);
let response = '';

client2.setEncoding('utf8');

client2.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

if (response.endsWith('0\r\n\r\n')) {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

const errOrEnd = common.mustSucceed(function(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

const errOrEnd = common.mustSucceed(function(err) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-headers-timeout-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ server.listen(0, common.mustCall(() => {
let second = false;
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCallAtLeast((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

// First response has ended
if (!second && response.endsWith('\r\n\r\n')) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-headers-timeout-pipelining.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
let second = false;
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCallAtLeast((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

// First response has ended
if (!second && response.endsWith('\r\n\r\n')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

client.resume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

const errOrEnd = common.mustSucceed(function(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

const errOrEnd = common.mustSucceed(function(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

const errOrEnd = common.mustSucceed(function(err) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-request-timeout-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ server.listen(0, common.mustCall(() => {
let second = false;
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCallAtLeast((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

// First response has ended
if (!second && response.endsWith('\r\n\r\n')) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-request-timeout-pipelining.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ server.listen(0, common.mustCall(() => {
let second = false;
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCallAtLeast((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

// First response has ended
if (!second && response.endsWith('\r\n\r\n')) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-request-timeout-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ server.listen(0, common.mustCall(() => {
const client = connect(server.address().port);
let response = '';

client.setEncoding('utf8');
client.on('data', common.mustCallAtLeast((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}, 1));

client.on('end', common.mustCall(() => {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-http-server-request-timeouts-mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ function createClient(server) {
completed: false
};

request.client.setEncoding('utf8');
request.client.on('data', common.mustCallAtLeast((chunk) => {
request.response += chunk.toString('utf-8');
request.response += chunk;
}));

request.client.on('end', common.mustCall(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ server.listen(0, common.mustSucceed(() => {
let response = '';

client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

client.setEncoding('utf8');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-transfer-encoding-smuggling.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ server.listen(0, common.mustSucceed(() => {
// Verify that the server listener is never called

client.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;
}));

client.setEncoding('utf8');
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-https-server-close-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ server.listen(0, function() {
const client2 = connect({ port, rejectUnauthorized: false });
let response = '';

client2.setEncoding('utf8');
client2.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

if (response.endsWith('0\r\n\r\n')) {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-https-server-close-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ server.listen(0, function() {
const client2 = connect({ port, rejectUnauthorized: false });
let response = '';

client2.setEncoding('utf8');
client2.on('data', common.mustCall((chunk) => {
response += chunk.toString('utf-8');
response += chunk;

if (response.endsWith('0\r\n\r\n')) {
assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
Expand Down