mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
bf6ce47259
Move tmpdir functionality to its own module (common/tmpdir). PR-URL: https://github.com/nodejs/node/pull/17856 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
40 lines
922 B
JavaScript
40 lines
922 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
let socketsCreated = 0;
|
|
|
|
class Agent extends http.Agent {
|
|
createConnection(options, oncreate) {
|
|
const socket = super.createConnection(options, oncreate);
|
|
socketsCreated++;
|
|
return socket;
|
|
}
|
|
}
|
|
|
|
const server = http.createServer((req, res) => res.end());
|
|
|
|
const socketPath = common.PIPE;
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
server.listen(socketPath, common.mustCall(() => {
|
|
const agent = new Agent({
|
|
keepAlive: true,
|
|
maxSockets: 1
|
|
});
|
|
|
|
http.get({ agent, socketPath }, (res) => res.resume());
|
|
|
|
const req = http.get({ agent, socketPath }, common.mustNotCall());
|
|
req.abort();
|
|
|
|
http.get({ agent, socketPath }, common.mustCall((res) => {
|
|
res.resume();
|
|
assert.strictEqual(socketsCreated, 1);
|
|
agent.destroy();
|
|
server.close();
|
|
}));
|
|
}));
|