Skip to content

Commit 5822f47

Browse files
santigimenoevanlucas
authored andcommitted
test: remove the use of curl in the test suite
There were 2 tests using curl: `test-http-304.js` is removed because it was initially included to test that the 304 response does not contain a body, and this is already covered by `test-http-chunked-304.js`. `test-http-curl-chunk-problem` has been renamed and refactored so instead of using curl, it uses 2 child node processes: one for sending the HTTP request and the other to calculate the sha1sum. Originally, this test was introduced to fix a bug in `[email protected]`, and it was not fixed until `[email protected]`. A modified version of this test has been run with `[email protected]` and reproduces the problem. This same test has been run with `[email protected]` and runs correctly. Fixes: #5174 PR-URL: #5750 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 5dc8df2 commit 5822f47

File tree

3 files changed

+93
-89
lines changed

3 files changed

+93
-89
lines changed

test/parallel/test-http-304.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'use strict';
2+
// http://groups.google.com/group/nodejs/browse_thread/thread/f66cd3c960406919
3+
const common = require('../common');
4+
const assert = require('assert');
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
return;
8+
}
9+
10+
if (process.argv[2] === 'request') {
11+
const http = require('http');
12+
const options = {
13+
port: common.PORT,
14+
path : '/'
15+
};
16+
17+
http.get(options, (res) => {
18+
res.pipe(process.stdout);
19+
});
20+
21+
return;
22+
}
23+
24+
if (process.argv[2] === 'shasum') {
25+
const crypto = require('crypto');
26+
const shasum = crypto.createHash('sha1');
27+
process.stdin.on('data', (d) => {
28+
shasum.update(d);
29+
});
30+
31+
process.stdin.on('close', () => {
32+
process.stdout.write(shasum.digest('hex'));
33+
});
34+
35+
return;
36+
}
37+
38+
const http = require('http');
39+
const cp = require('child_process');
40+
41+
const filename = require('path').join(common.tmpDir, 'big');
42+
43+
function executeRequest(cb) {
44+
cp.exec([process.execPath,
45+
__filename,
46+
'request',
47+
'|',
48+
process.execPath,
49+
__filename,
50+
'shasum' ].join(' '),
51+
(err, stdout, stderr) => {
52+
if (err) throw err;
53+
assert.equal('8c206a1a87599f532ce68675536f0b1546900d7a',
54+
stdout.slice(0, 40));
55+
cb();
56+
}
57+
);
58+
}
59+
60+
61+
common.refreshTmpDir();
62+
63+
const ddcmd = common.ddCommand(filename, 10240);
64+
65+
cp.exec(ddcmd, function(err, stdout, stderr) {
66+
if (err) throw err;
67+
const server = http.createServer(function(req, res) {
68+
res.writeHead(200);
69+
70+
// Create the subprocess
71+
const cat = cp.spawn('cat', [filename]);
72+
73+
// Stream the data through to the response as binary chunks
74+
cat.stdout.on('data', (data) => {
75+
res.write(data);
76+
});
77+
78+
cat.stdout.on('end', () => res.end());
79+
80+
// End the response on exit (and log errors)
81+
cat.on('exit', (code) => {
82+
if (code !== 0) {
83+
console.error('subprocess exited with code ' + code);
84+
process.exit(1);
85+
}
86+
});
87+
88+
});
89+
90+
server.listen(common.PORT, () => {
91+
executeRequest(() => server.close());
92+
});
93+
});

test/parallel/test-http-curl-chunk-problem.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)