11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst server = http.Server(common.mustCall((req, res) => { 71cb0ef41Sopenharmony_ci res.writeHead(200); 81cb0ef41Sopenharmony_ci res.end('Hello, World!'); 91cb0ef41Sopenharmony_ci})); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 121cb0ef41Sopenharmony_ci const agent = new http.Agent(); 131cb0ef41Sopenharmony_ci const name = agent.getName({ port: server.address().port }); 141cb0ef41Sopenharmony_ci http.globalAgent = agent; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci makeRequest(); 171cb0ef41Sopenharmony_ci assert(name in agent.sockets); // Agent has indeed been used 181cb0ef41Sopenharmony_ci})); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction makeRequest() { 211cb0ef41Sopenharmony_ci const req = http.get({ 221cb0ef41Sopenharmony_ci port: server.address().port 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci req.on('close', () => { 251cb0ef41Sopenharmony_ci assert.strictEqual(req.destroyed, true); 261cb0ef41Sopenharmony_ci server.close(); 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci} 29