-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: rename tests with descriptive filenames
Refs: #19105 Refs: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#test-structure PR-URL: #19608 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
- Loading branch information
Showing
11 changed files
with
278 additions
and
231 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) common.skip('missing crypto'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
// An HTTP Agent reuses a TLSSocket, and makes a failed call to `asyncReset`. | ||
// Refs: https://github.com/nodejs/node/issues/13045 | ||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
|
||
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)); | ||
}) | ||
); |
75 changes: 75 additions & 0 deletions
75
test/parallel/test-child-process-fork-closed-channel-segfault.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// Before https://github.com/nodejs/node/pull/2847 a child process trying | ||
// (asynchronously) to use the closed channel to it's creator caused a segfault. | ||
|
||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
|
||
if (!cluster.isMaster) { | ||
// Exit on first received handle to leave the queue non-empty in master | ||
process.on('message', function() { | ||
process.exit(1); | ||
}); | ||
return; | ||
} | ||
|
||
const server = net | ||
.createServer(function(s) { | ||
if (common.isWindows) { | ||
s.on('error', function(err) { | ||
// Prevent possible ECONNRESET errors from popping up | ||
if (err.code !== 'ECONNRESET') throw err; | ||
}); | ||
} | ||
setTimeout(function() { | ||
s.destroy(); | ||
}, 100); | ||
}) | ||
.listen(0, function() { | ||
const worker = cluster.fork(); | ||
|
||
function send(callback) { | ||
const s = net.connect(server.address().port, function() { | ||
worker.send({}, s, callback); | ||
}); | ||
|
||
// https://github.com/nodejs/node/issues/3635#issuecomment-157714683 | ||
// ECONNREFUSED or ECONNRESET errors can happen if this connection is | ||
// still establishing while the server has already closed. | ||
// EMFILE can happen if the worker __and__ the server had already closed. | ||
s.on('error', function(err) { | ||
if ( | ||
err.code !== 'ECONNRESET' && | ||
err.code !== 'ECONNREFUSED' && | ||
err.code !== 'EMFILE' | ||
) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
|
||
worker.process.once( | ||
'close', | ||
common.mustCall(function() { | ||
// Otherwise the crash on `channel.fd` access may happen | ||
assert.strictEqual(worker.process.channel, null); | ||
server.close(); | ||
}) | ||
); | ||
|
||
worker.on('online', function() { | ||
send(function(err) { | ||
assert.ifError(err); | ||
send(function(err) { | ||
// Ignore errors when sending the second handle because the worker | ||
// may already have exited. | ||
if (err && err.message !== 'Channel closed') { | ||
throw err; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This test ensures that Node.js doesn't crash with an AssertionError at | ||
// `ServerResponse.resOnFinish` because of an out-of-order 'finish' bug in | ||
// pipelining. | ||
// https://github.com/nodejs/node/issues/2639 | ||
|
||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
const COUNT = 10; | ||
|
||
const server = http | ||
.createServer( | ||
common.mustCall((req, res) => { | ||
// Close the server, we have only one TCP connection anyway | ||
server.close(); | ||
res.writeHead(200); | ||
res.write('data'); | ||
|
||
setTimeout(function() { | ||
res.end(); | ||
}, (Math.random() * 100) | 0); | ||
}, COUNT) | ||
) | ||
.listen(0, function() { | ||
const s = net.connect(this.address().port); | ||
|
||
const big = 'GET / HTTP/1.0\r\n\r\n'.repeat(COUNT); | ||
|
||
s.write(big); | ||
s.resume(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.