Permalink
Browse files

test: test cases for #1577

  • Loading branch information...
bnoordhuis committed Aug 29, 2011
1 parent b5144b2 commit 7d4cdaa2cb142d75b01ac6cd51baea22fc761925
@@ -0,0 +1,39 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var https = require('https');
+
+var caughtError = false;
+
+var req = https.get({host:'127.0.0.1', port:common.PORT}, function(res) {
+ assert.ok(false); // should never run
+});
+
+req.on('error', function(e) {
+ assert.equal(e.code, 'ECONNREFUSED');
+ caughtError = true;
+});
+
+process.on('exit', function() {
+ assert.equal(caughtError, true);
+});
@@ -0,0 +1,52 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var https = require('https');
+var fs = require('fs');
+
+var caughtError = false;
+
+var options = {
+ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
+ cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
+};
+
+var server = https.createServer(options, function(req, res) {
+ req.destroy();
+ server.close();
+});
+
+server.listen(common.PORT, '127.0.0.1', function() {
+ var req = https.get({host:'127.0.0.1', port:common.PORT}, function(res) {
+ assert.ok(false); // should never run
+ });
+
+ req.on('error', function(e) {
+ assert.ok(/socket hang up/.test(e.message)); // less than ideal
+ caughtError = true;

This comment has been minimized.

Show comment
Hide comment
@ry

ry Sep 8, 2011

please ref joyent#1672 here so that we can update the test once we fix this

@ry

ry Sep 8, 2011

please ref joyent#1672 here so that we can update the test once we fix this

+ });
+});
+
+process.on('exit', function() {
+ assert.equal(caughtError, true);
+});
@@ -0,0 +1,85 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var https = require('https');
+var cp = require('child_process');
+var fs = require('fs');
+
+
+function do_server() {

This comment has been minimized.

Show comment
Hide comment
@ry

ry Sep 8, 2011

camelcase

@ry

ry Sep 8, 2011

camelcase

+ var options = {
+ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
+ cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
+ };
+
+ // simulate a server aborting the request half-way through
+ var server = https.createServer(options, function(req, res) {
+ res.writeHead(200, {'Content-Type':'text/plain',
+ 'Transfer-Encoding':'chunked'});
+ res.write('PING');
+ res.destroy();
+ process.exit(42);
+ });
+
+ server.listen(common.PORT, '127.0.0.1', function() {
+ console.error('READY'); // signals parent
+ });
+}
+
+
+function do_client() {
+ var closed = false;
+
+ var req = https.get({host:'127.0.0.1', port:common.PORT}, function(res) {
+ res.on('data', function(data) {
+ assert.equal('PING', data);
+ });
+
+ res.on('close', function() {
+ closed = true;
+ });

This comment has been minimized.

Show comment
Hide comment
@ry

ry Sep 8, 2011

shouldnt we get an error here?

@ry

ry Sep 8, 2011

shouldnt we get an error here?

+ });
+
+ process.on('exit', function() {
+ assert.equal(true, closed);
+ });
+}
+
+
+if (process.argv[2] == '--server') {
+ do_server();
+}
+else {
+ // start the server in a child process
+ var child = cp.spawn(process.argv[0], [process.argv[1], '--server']);
+
+ // wait for the server to become ready
+ child.stderr.on('data', function(data) {
+ assert.equal("READY\n", data);
+ do_client();
+ });
+
+ child.on('exit', function(status) {
+ assert.equal(42, status);
+ });
+}

1 comment on commit 7d4cdaa

@ry

This comment has been minimized.

Show comment
Hide comment
@ry

ry Sep 8, 2011

Sorry I reviewed before realizing that these actually don't demonstrate the bug.

ry commented on 7d4cdaa Sep 8, 2011

Sorry I reviewed before realizing that these actually don't demonstrate the bug.

Please sign in to comment.