test: improve test-http-agent-destroyed-socket.js
* wrap callbacks in mustCall() * Wrap the callbacks which make assertions in common.mustcall() to ensure they are called PR-URL: https://github.com/nodejs/node/pull/11201 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
c8fff70079
commit
3d2bd7abda
@ -1,15 +1,15 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
|
||||
const server = http.createServer(function(req, res) {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
}).listen(0, function() {
|
||||
}).listen(0, common.mustCall(function() {
|
||||
const agent = new http.Agent({maxSockets: 1});
|
||||
|
||||
agent.on('free', function(socket, host, port) {
|
||||
agent.on('free', function(socket) {
|
||||
console.log('freeing socket. destroyed? ', socket.destroyed);
|
||||
});
|
||||
|
||||
@ -20,7 +20,7 @@ const server = http.createServer(function(req, res) {
|
||||
path: '/'
|
||||
};
|
||||
|
||||
const request1 = http.get(requestOptions, function(response) {
|
||||
const request1 = http.get(requestOptions, common.mustCall(function(response) {
|
||||
// assert request2 is queued in the agent
|
||||
const key = agent.getName(requestOptions);
|
||||
assert.strictEqual(agent.requests[key].length, 1);
|
||||
@ -29,7 +29,7 @@ const server = http.createServer(function(req, res) {
|
||||
console.log('request1 socket closed');
|
||||
});
|
||||
response.pipe(process.stdout);
|
||||
response.on('end', function() {
|
||||
response.on('end', common.mustCall(function() {
|
||||
console.log('response1 done');
|
||||
/////////////////////////////////
|
||||
//
|
||||
@ -48,17 +48,17 @@ const server = http.createServer(function(req, res) {
|
||||
// assert request2 was removed from the queue
|
||||
assert(!agent.requests[key]);
|
||||
console.log("waiting for request2.onSocket's nextTick");
|
||||
process.nextTick(function() {
|
||||
process.nextTick(common.mustCall(function() {
|
||||
// assert that the same socket was not assigned to request2,
|
||||
// since it was destroyed.
|
||||
assert.notStrictEqual(request1.socket, request2.socket);
|
||||
assert(!request2.socket.destroyed, 'the socket is destroyed');
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
const request2 = http.get(requestOptions, function(response) {
|
||||
const request2 = http.get(requestOptions, common.mustCall(function(response) {
|
||||
assert(!request2.socket.destroyed);
|
||||
assert(request1.socket.destroyed);
|
||||
// assert not reusing the same socket, since it was destroyed.
|
||||
@ -82,5 +82,5 @@ const server = http.createServer(function(req, res) {
|
||||
if (gotResponseEnd && gotClose)
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user