mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
7535a94c8a
Adds a new `../common/fixtures' module to begin normalizing `test/fixtures` use. Our test code is a bit inconsistent with regards to use of the fixtures directory. Some code uses `path.join()`, some code uses string concats, some other code uses template strings, etc. In mnay cases, significant duplication of code is seen when accessing fixture files, etc. This updates many (but by no means all) of the tests in the test suite to use the new consistent API. There are still many more to update, which would make an excelent Code-n-Learn exercise. PR-URL: https://github.com/nodejs/node/pull/14332 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/13045
|
|
// An HTTP Agent reuses a TLSSocket, and makes a failed call to `asyncReset`.
|
|
|
|
const assert = require('assert');
|
|
const https = require('https');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const serverOptions = {
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem'),
|
|
ca: fixtures.readKey('ca1-cert.pem')
|
|
};
|
|
|
|
const server = https.createServer(serverOptions, common.mustCall((req, res) => {
|
|
res.end('hello world\n');
|
|
}, 2));
|
|
|
|
server.listen(0, common.mustCall(function() {
|
|
const port = this.address().port;
|
|
const clientOptions = {
|
|
agent: new https.Agent({
|
|
keepAlive: true,
|
|
rejectUnauthorized: false
|
|
}),
|
|
port: port
|
|
};
|
|
|
|
const req = https.get(clientOptions, common.mustCall((res) => {
|
|
assert.strictEqual(res.statusCode, 200);
|
|
res.on('error', (err) => assert.fail(err));
|
|
res.socket.on('error', (err) => assert.fail(err));
|
|
res.resume();
|
|
// drain the socket and wait for it to be free to reuse
|
|
res.socket.once('free', () => {
|
|
// This is the pain point. Internally the Agent will call
|
|
// `socket._handle.asyncReset()` and if the _handle does not implement
|
|
// `asyncReset` this will throw TypeError
|
|
const req2 = https.get(clientOptions, common.mustCall((res2) => {
|
|
assert.strictEqual(res.statusCode, 200);
|
|
res2.on('error', (err) => assert.fail(err));
|
|
res2.socket.on('error', (err) => assert.fail(err));
|
|
// this should be the end of the test
|
|
res2.destroy();
|
|
server.close();
|
|
}));
|
|
req2.on('error', (err) => assert.fail(err));
|
|
});
|
|
}));
|
|
req.on('error', (err) => assert.fail(err));
|
|
}));
|