-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
test: improve numerous http tests #12930
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,26 +34,21 @@ function test(handler, request_generator, response_validator) { | |
let server_response = ''; | ||
|
||
server.listen(0); | ||
server.on('listening', function() { | ||
const c = net.createConnection(this.address().port); | ||
server.on('listening', common.mustCall(() => { | ||
const c = net.createConnection(server.address().port); | ||
|
||
c.setEncoding('utf8'); | ||
|
||
c.on('connect', function() { | ||
c.write(request_generator()); | ||
}); | ||
c.on('connect', common.mustCall(() => c.write(request_generator()))); | ||
c.on('data', common.mustCall((chunk) => server_response += chunk)); | ||
|
||
|
||
c.on('data', function(chunk) { | ||
server_response += chunk; | ||
}); | ||
|
||
c.on('end', common.mustCall(function() { | ||
c.on('end', common.mustCall(() => { | ||
client_got_eof = true; | ||
c.end(); | ||
server.close(); | ||
response_validator(server_response, client_got_eof, false); | ||
})); | ||
}); | ||
})); | ||
} | ||
|
||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,42 +23,24 @@ | |
const common = require('../common'); | ||
const http = require('http'); | ||
|
||
const server = http.Server(function(req, res) { | ||
console.log('Server accepted request.'); | ||
const server = http.Server(common.mustCall((req, res) => { | ||
res.writeHead(200); | ||
res.write('Part of my res.'); | ||
|
||
res.destroy(); | ||
}); | ||
})); | ||
|
||
server.listen(0, common.mustCall(function() { | ||
server.listen(0, common.mustCall(() => { | ||
http.get({ | ||
port: this.address().port, | ||
port: server.address().port, | ||
headers: { connection: 'keep-alive' } | ||
}, common.mustCall(function(res) { | ||
}, common.mustCall((res) => { | ||
server.close(); | ||
|
||
console.log(`Got res: ${res.statusCode}`); | ||
console.dir(res.headers); | ||
|
||
res.on('data', function(chunk) { | ||
console.log(`Read ${chunk.length} bytes`); | ||
console.log(' chunk=%j', chunk.toString()); | ||
}); | ||
|
||
res.on('end', function() { | ||
console.log('Response ended.'); | ||
}); | ||
|
||
res.on('aborted', function() { | ||
console.log('Response aborted.'); | ||
}); | ||
|
||
res.socket.on('close', function() { | ||
console.log('socket closed, but not res'); | ||
}); | ||
|
||
// it would be nice if this worked: | ||
res.on('data', common.mustCall()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe replace with the longer but more explicit: let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', common.mustCall(() => {
assert.strictEqual(data, 'Part of my res.');
})); This way it verifies all of these:
|
||
res.on('end', common.mustCall()); | ||
res.on('aborted', common.mustCall()); | ||
res.socket.on('close', common.mustCall()); | ||
res.on('close', common.mustCall()); | ||
})); | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/s/127.0.0.1/common.localhostIPv4/