1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
25 // Uploading a big file via HTTPS causes node to drop out of the event loop.
26 // https://github.com/joyent/node/issues/892
27 // In this test we set up an HTTPS in this process and launch a subprocess
28 // to POST a 32mb file to us. A bug in the pause/resume functionality of the
29 // TLS server causes the child process to exit cleanly before having sent
31 var common = require('../common');
32 var assert = require('assert');
33 var spawn = require('child_process').spawn;
34 var https = require('https');
35 var fs = require('fs');
40 var bytesExpected = 1024 * 1024 * 32;
41 var gotResponse = false;
45 var childScript = require('path').join(common.fixturesDir, 'GH-892-request.js');
47 function makeRequest() {
51 var stderrBuffer = '';
53 // Pass along --trace-deprecation/--throw-deprecation in
54 // process.execArgv to track down nextTick recursion errors
55 // more easily. Also, this is handy when using this test to
56 // view V8 opt/deopt behavior.
57 var args = process.execArgv.concat([ childScript,
61 var child = spawn(process.execPath, args);
63 child.on('exit', function(code) {
64 assert.ok(/DONE/.test(stderrBuffer));
65 assert.equal(0, code);
68 // The following two lines forward the stdio from the child
69 // to parent process for debugging.
70 child.stderr.pipe(process.stderr);
71 child.stdout.pipe(process.stdout);
74 // Buffer the stderr so that we can check that it got 'DONE'
75 child.stderr.setEncoding('ascii');
76 child.stderr.on('data', function(d) {
83 key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
84 cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
89 var server = https.Server(serverOptions, function(req, res) {
90 // Close the server immediately. This test is only doing a single upload.
91 // We need to make sure the server isn't keeping the event loop alive
92 // while the upload is in progress.
95 req.on('data', function(d) {
96 process.stderr.write('.');
97 uploadCount += d.length;
100 req.on('end', function() {
101 assert.equal(bytesExpected, uploadCount);
102 res.writeHead(200, {'content-type': 'text/plain'});
103 res.end('successful upload\n');
107 server.listen(common.PORT, function() {
108 console.log('expecting %d bytes', bytesExpected);
112 process.on('exit', function() {
113 console.error('got %d bytes', uploadCount);
114 assert.equal(uploadCount, bytesExpected);