Skip to content

Commit 278e8af

Browse files
ryzokukentargos
authored andcommittedApr 2, 2018
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 0786161 commit 278e8af

11 files changed

+278
-231
lines changed
 

‎test/parallel/test-async-wrap-GH13045.js

-55
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto) common.skip('missing crypto');
4+
const fixtures = require('../common/fixtures');
5+
6+
// An HTTP Agent reuses a TLSSocket, and makes a failed call to `asyncReset`.
7+
// Refs: https://github.com/nodejs/node/issues/13045
8+
9+
const assert = require('assert');
10+
const https = require('https');
11+
12+
const serverOptions = {
13+
key: fixtures.readKey('agent1-key.pem'),
14+
cert: fixtures.readKey('agent1-cert.pem'),
15+
ca: fixtures.readKey('ca1-cert.pem')
16+
};
17+
18+
const server = https.createServer(
19+
serverOptions,
20+
common.mustCall((req, res) => {
21+
res.end('hello world\n');
22+
}, 2)
23+
);
24+
25+
server.listen(
26+
0,
27+
common.mustCall(function() {
28+
const port = this.address().port;
29+
const clientOptions = {
30+
agent: new https.Agent({
31+
keepAlive: true,
32+
rejectUnauthorized: false
33+
}),
34+
port: port
35+
};
36+
37+
const req = https.get(
38+
clientOptions,
39+
common.mustCall((res) => {
40+
assert.strictEqual(res.statusCode, 200);
41+
res.on('error', (err) => assert.fail(err));
42+
res.socket.on('error', (err) => assert.fail(err));
43+
res.resume();
44+
// drain the socket and wait for it to be free to reuse
45+
res.socket.once('free', () => {
46+
// This is the pain point. Internally the Agent will call
47+
// `socket._handle.asyncReset()` and if the _handle does not implement
48+
// `asyncReset` this will throw TypeError
49+
const req2 = https.get(
50+
clientOptions,
51+
common.mustCall((res2) => {
52+
assert.strictEqual(res.statusCode, 200);
53+
res2.on('error', (err) => assert.fail(err));
54+
res2.socket.on('error', (err) => assert.fail(err));
55+
// this should be the end of the test
56+
res2.destroy();
57+
server.close();
58+
})
59+
);
60+
req2.on('error', (err) => assert.fail(err));
61+
});
62+
})
63+
);
64+
req.on('error', (err) => assert.fail(err));
65+
})
66+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Before https://github.com/nodejs/node/pull/2847 a child process trying
5+
// (asynchronously) to use the closed channel to it's creator caused a segfault.
6+
7+
const assert = require('assert');
8+
const cluster = require('cluster');
9+
const net = require('net');
10+
11+
if (!cluster.isMaster) {
12+
// Exit on first received handle to leave the queue non-empty in master
13+
process.on('message', function() {
14+
process.exit(1);
15+
});
16+
return;
17+
}
18+
19+
const server = net
20+
.createServer(function(s) {
21+
if (common.isWindows) {
22+
s.on('error', function(err) {
23+
// Prevent possible ECONNRESET errors from popping up
24+
if (err.code !== 'ECONNRESET') throw err;
25+
});
26+
}
27+
setTimeout(function() {
28+
s.destroy();
29+
}, 100);
30+
})
31+
.listen(0, function() {
32+
const worker = cluster.fork();
33+
34+
function send(callback) {
35+
const s = net.connect(server.address().port, function() {
36+
worker.send({}, s, callback);
37+
});
38+
39+
// https://github.com/nodejs/node/issues/3635#issuecomment-157714683
40+
// ECONNREFUSED or ECONNRESET errors can happen if this connection is
41+
// still establishing while the server has already closed.
42+
// EMFILE can happen if the worker __and__ the server had already closed.
43+
s.on('error', function(err) {
44+
if (
45+
err.code !== 'ECONNRESET' &&
46+
err.code !== 'ECONNREFUSED' &&
47+
err.code !== 'EMFILE'
48+
) {
49+
throw err;
50+
}
51+
});
52+
}
53+
54+
worker.process.once(
55+
'close',
56+
common.mustCall(function() {
57+
// Otherwise the crash on `channel.fd` access may happen
58+
assert.strictEqual(worker.process.channel, null);
59+
server.close();
60+
})
61+
);
62+
63+
worker.on('online', function() {
64+
send(function(err) {
65+
assert.ifError(err);
66+
send(function(err) {
67+
// Ignore errors when sending the second handle because the worker
68+
// may already have exited.
69+
if (err && err.message !== 'Channel closed') {
70+
throw err;
71+
}
72+
});
73+
});
74+
});
75+
});

‎test/parallel/test-child-process-fork-regr-gh-2847.js

-69
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// This test ensures that Node.js doesn't crash with an AssertionError at
5+
// `ServerResponse.resOnFinish` because of an out-of-order 'finish' bug in
6+
// pipelining.
7+
// https://github.com/nodejs/node/issues/2639
8+
9+
const http = require('http');
10+
const net = require('net');
11+
12+
const COUNT = 10;
13+
14+
const server = http
15+
.createServer(
16+
common.mustCall((req, res) => {
17+
// Close the server, we have only one TCP connection anyway
18+
server.close();
19+
res.writeHead(200);
20+
res.write('data');
21+
22+
setTimeout(function() {
23+
res.end();
24+
}, (Math.random() * 100) | 0);
25+
}, COUNT)
26+
)
27+
.listen(0, function() {
28+
const s = net.connect(this.address().port);
29+
30+
const big = 'GET / HTTP/1.0\r\n\r\n'.repeat(COUNT);
31+
32+
s.write(big);
33+
s.resume();
34+
});

‎test/parallel/test-http-pipeline-regr-2639.js

-24
This file was deleted.

‎test/parallel/test-http-pipeline-regr-3332.js

-27
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.