mirror of https://github.com/lukechilds/node.git
Browse Source
Conflicts: ChangeLog doc/template.html lib/cluster.js lib/http.js lib/tls.js src/node.h src/node_version.h test/simple/test-cluster-kill-workers.jsv0.7.4-release
Fedor Indutny
13 years ago
73 changed files with 1874 additions and 385 deletions
@ -0,0 +1,59 @@ |
|||
// 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.
|
|||
|
|||
// Installing a custom uncaughtException handler should override the default
|
|||
// one that the cluster module installs.
|
|||
// https://github.com/joyent/node/issues/2556
|
|||
|
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var cluster = require('cluster'); |
|||
var fork = require('child_process').fork; |
|||
|
|||
var MAGIC_EXIT_CODE = 42; |
|||
|
|||
var isTestRunner = process.argv[2] != 'child'; |
|||
|
|||
if (isTestRunner) { |
|||
var exitCode = -1; |
|||
|
|||
process.on('exit', function() { |
|||
assert.equal(exitCode, MAGIC_EXIT_CODE); |
|||
}); |
|||
|
|||
var master = fork(__filename, ['child']); |
|||
master.on('exit', function(code) { |
|||
exitCode = code; |
|||
}); |
|||
} |
|||
else if (cluster.isMaster) { |
|||
process.on('uncaughtException', function() { |
|||
process.nextTick(function() { |
|||
process.exit(MAGIC_EXIT_CODE); |
|||
}); |
|||
}); |
|||
|
|||
cluster.fork(); |
|||
throw new Error('kill master'); |
|||
} |
|||
else { // worker
|
|||
process.exit(); |
|||
} |
@ -0,0 +1,160 @@ |
|||
// 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'), |
|||
assert = require('assert'), |
|||
cluster = require('cluster'), |
|||
dgram = require('dgram'), |
|||
util = require('util'), |
|||
assert = require('assert'), |
|||
Buffer = require('buffer').Buffer, |
|||
LOCAL_BROADCAST_HOST = '255.255.255.255', |
|||
messages = [ |
|||
new Buffer('First message to send'), |
|||
new Buffer('Second message to send'), |
|||
new Buffer('Third message to send'), |
|||
new Buffer('Fourth message to send') |
|||
]; |
|||
|
|||
if (cluster.isMaster) { |
|||
var workers = {}, |
|||
listeners = 3, |
|||
listening = 0, |
|||
i = 0, |
|||
done = 0; |
|||
|
|||
//launch child processes
|
|||
for (var x = 0; x < listeners; x++) { |
|||
(function () { |
|||
var worker = cluster.fork(); |
|||
workers[worker.pid] = worker; |
|||
|
|||
worker.messagesReceived = []; |
|||
|
|||
worker.on('message', function (msg) { |
|||
if (msg.listening) { |
|||
listening += 1; |
|||
|
|||
if (listening === listeners) { |
|||
//all child process are listening, so start sending
|
|||
sendSocket.sendNext(); |
|||
} |
|||
} |
|||
else if (msg.message) { |
|||
worker.messagesReceived.push(msg.message); |
|||
|
|||
if (worker.messagesReceived.length === messages.length) { |
|||
done += 1; |
|||
console.error('%d received %d messages total.', worker.pid, |
|||
worker.messagesReceived.length); |
|||
} |
|||
|
|||
if (done === listeners) { |
|||
console.error('All workers have received the required number of ' |
|||
+ 'messages. Will now compare.'); |
|||
|
|||
Object.keys(workers).forEach(function (pid) { |
|||
var worker = workers[pid]; |
|||
|
|||
var count = 0; |
|||
|
|||
worker.messagesReceived.forEach(function(buf) { |
|||
for (var i = 0; i < messages.length; ++i) { |
|||
if (buf.toString() === messages[i].toString()) { |
|||
count++; |
|||
break; |
|||
} |
|||
} |
|||
}); |
|||
|
|||
console.error('%d received %d matching messges.', worker.pid |
|||
, count); |
|||
|
|||
assert.equal(count, messages.length |
|||
,'A worker received an invalid multicast message'); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
})(x); |
|||
} |
|||
|
|||
var sendSocket = dgram.createSocket('udp4'); |
|||
|
|||
sendSocket.bind(common.PORT); |
|||
sendSocket.setBroadcast(true); |
|||
|
|||
sendSocket.on('close', function() { |
|||
console.error('sendSocket closed'); |
|||
}); |
|||
|
|||
sendSocket.sendNext = function() { |
|||
var buf = messages[i++]; |
|||
|
|||
if (!buf) { |
|||
try { sendSocket.close(); } catch (e) {} |
|||
return; |
|||
} |
|||
|
|||
sendSocket.send(buf, 0, buf.length, |
|||
common.PORT, LOCAL_BROADCAST_HOST, function(err) { |
|||
|
|||
if (err) throw err; |
|||
|
|||
console.error('sent %s to %s:%s', util.inspect(buf.toString()) |
|||
, LOCAL_BROADCAST_HOST, common.PORT); |
|||
|
|||
process.nextTick(sendSocket.sendNext); |
|||
}); |
|||
}; |
|||
} |
|||
|
|||
if (!cluster.isMaster) { |
|||
var receivedMessages = []; |
|||
var listenSocket = dgram.createSocket('udp4'); |
|||
|
|||
listenSocket.on('message', function(buf, rinfo) { |
|||
console.error('%s received %s from %j', process.pid |
|||
, util.inspect(buf.toString()), rinfo); |
|||
|
|||
receivedMessages.push(buf); |
|||
|
|||
process.send({ message : buf.toString() }); |
|||
|
|||
if (receivedMessages.length == messages.length) { |
|||
listenSocket.dropMembership(LOCAL_BROADCAST_HOST); |
|||
process.nextTick(function() { // TODO should be changed to below.
|
|||
// listenSocket.dropMembership(LOCAL_BROADCAST_HOST, function() {
|
|||
listenSocket.close(); |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
listenSocket.on('close', function() { |
|||
process.exit(); |
|||
}); |
|||
|
|||
listenSocket.on('listening', function() { |
|||
process.send({ listening : true }); |
|||
}); |
|||
|
|||
listenSocket.bind(common.PORT); |
|||
} |
@ -0,0 +1,160 @@ |
|||
// 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'), |
|||
assert = require('assert'), |
|||
cluster = require('cluster'), |
|||
dgram = require('dgram'), |
|||
util = require('util'), |
|||
assert = require('assert'), |
|||
Buffer = require('buffer').Buffer, |
|||
LOCAL_BROADCAST_HOST = '224.0.0.1', |
|||
messages = [ |
|||
new Buffer('First message to send'), |
|||
new Buffer('Second message to send'), |
|||
new Buffer('Third message to send'), |
|||
new Buffer('Fourth message to send') |
|||
]; |
|||
|
|||
if (cluster.isMaster) { |
|||
var workers = {}, |
|||
listeners = 3, |
|||
listening = 0, |
|||
i = 0, |
|||
done = 0; |
|||
|
|||
//launch child processes
|
|||
for (var x = 0; x < listeners; x++) { |
|||
(function () { |
|||
var worker = cluster.fork(); |
|||
workers[worker.pid] = worker; |
|||
|
|||
worker.messagesReceived = []; |
|||
|
|||
worker.on('message', function (msg) { |
|||
if (msg.listening) { |
|||
listening += 1; |
|||
|
|||
if (listening === listeners) { |
|||
//all child process are listening, so start sending
|
|||
sendSocket.sendNext(); |
|||
} |
|||
} |
|||
else if (msg.message) { |
|||
worker.messagesReceived.push(msg.message); |
|||
|
|||
if (worker.messagesReceived.length === messages.length) { |
|||
done += 1; |
|||
console.error('%d received %d messages total.', worker.pid, |
|||
worker.messagesReceived.length); |
|||
} |
|||
|
|||
if (done === listeners) { |
|||
console.error('All workers have received the required number of' |
|||
+ 'messages. Will now compare.'); |
|||
|
|||
Object.keys(workers).forEach(function (pid) { |
|||
var worker = workers[pid]; |
|||
|
|||
var count = 0; |
|||
|
|||
worker.messagesReceived.forEach(function(buf) { |
|||
for (var i = 0; i < messages.length; ++i) { |
|||
if (buf.toString() === messages[i].toString()) { |
|||
count++; |
|||
break; |
|||
} |
|||
} |
|||
}); |
|||
|
|||
console.error('%d received %d matching messges.', worker.pid |
|||
, count); |
|||
|
|||
assert.equal(count, messages.length |
|||
,'A worker received an invalid multicast message'); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
})(x); |
|||
} |
|||
|
|||
var sendSocket = dgram.createSocket('udp4'); |
|||
|
|||
//sendSocket.setBroadcast(true);
|
|||
//sendSocket.setMulticastTTL(1);
|
|||
//sendSocket.setMulticastLoopback(true);
|
|||
|
|||
sendSocket.on('close', function() { |
|||
console.error('sendSocket closed'); |
|||
}); |
|||
|
|||
sendSocket.sendNext = function() { |
|||
var buf = messages[i++]; |
|||
|
|||
if (!buf) { |
|||
try { sendSocket.close(); } catch (e) {} |
|||
return; |
|||
} |
|||
|
|||
sendSocket.send(buf, 0, buf.length, |
|||
common.PORT, LOCAL_BROADCAST_HOST, function(err) { |
|||
if (err) throw err; |
|||
console.error('sent %s to %s', util.inspect(buf.toString()), |
|||
LOCAL_BROADCAST_HOST + common.PORT); |
|||
process.nextTick(sendSocket.sendNext); |
|||
}); |
|||
}; |
|||
} |
|||
|
|||
if (!cluster.isMaster) { |
|||
var receivedMessages = []; |
|||
var listenSocket = dgram.createSocket('udp4'); |
|||
|
|||
listenSocket.addMembership(LOCAL_BROADCAST_HOST); |
|||
|
|||
listenSocket.on('message', function(buf, rinfo) { |
|||
console.error('%s received %s from %j', process.pid |
|||
,util.inspect(buf.toString()), rinfo); |
|||
|
|||
receivedMessages.push(buf); |
|||
|
|||
process.send({ message : buf.toString() }); |
|||
|
|||
if (receivedMessages.length == messages.length) { |
|||
listenSocket.dropMembership(LOCAL_BROADCAST_HOST); |
|||
process.nextTick(function() { // TODO should be changed to below.
|
|||
// listenSocket.dropMembership(LOCAL_BROADCAST_HOST, function() {
|
|||
listenSocket.close(); |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
listenSocket.on('close', function() { |
|||
process.exit(); |
|||
}); |
|||
|
|||
listenSocket.on('listening', function() { |
|||
process.send({ listening : true }); |
|||
}); |
|||
|
|||
listenSocket.bind(common.PORT); |
|||
} |
@ -0,0 +1,41 @@ |
|||
// 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'), |
|||
assert = require('assert'), |
|||
dgram = require('dgram'), |
|||
thrown = false, |
|||
socket = dgram.createSocket('udp4'); |
|||
|
|||
socket.bind(common.PORT); |
|||
socket.setMulticastTTL(16); |
|||
|
|||
//Try to set an invalid TTL (valid ttl is > 0 and < 256)
|
|||
try { |
|||
socket.setMulticastTTL(1000); |
|||
} catch (e) { |
|||
thrown = true; |
|||
} |
|||
|
|||
assert(thrown, 'Setting an invalid mutlicast TTL should throw some error'); |
|||
|
|||
//close the socket
|
|||
socket.close(); |
@ -0,0 +1,54 @@ |
|||
// 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 http = require('http'); |
|||
var N = 100; |
|||
var responses = 0; |
|||
|
|||
var server = http.createServer(function(req, res) { |
|||
res.end('Hello'); |
|||
}); |
|||
|
|||
server.listen(common.PORT, function() { |
|||
http.globalAgent.maxSockets = 1; |
|||
var parser; |
|||
for (var i = 0; i < N; ++i) { |
|||
(function makeRequest(i) { |
|||
var req = http.get({port: common.PORT}, function(res) { |
|||
if (!parser) { |
|||
parser = req.parser; |
|||
} else { |
|||
assert.strictEqual(req.parser, parser); |
|||
} |
|||
|
|||
if (++responses === N) { |
|||
server.close(); |
|||
} |
|||
}); |
|||
})(i); |
|||
} |
|||
}); |
|||
|
|||
process.on('exit', function() { |
|||
assert.equal(responses, N); |
|||
}); |
@ -0,0 +1,71 @@ |
|||
// 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 http = require('http'); |
|||
var net = require('net'); |
|||
|
|||
var SERVER_RESPONSES = [ |
|||
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n', |
|||
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', |
|||
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n', |
|||
'HTTP/1.1 200 ok\r\nContent-Length: 0\r\n\r\n', |
|||
'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: keep-alive\r\n\r\n', |
|||
'HTTP/1.1 200 ok\r\nContent-Length: 0\r\nConnection: close\r\n\r\n', |
|||
]; |
|||
var SHOULD_KEEP_ALIVE = [ |
|||
false, // HTTP/1.0, default
|
|||
true, // HTTP/1.0, Connection: keep-alive
|
|||
false, // HTTP/1.0, Connection: close
|
|||
true, // HTTP/1.1, default
|
|||
true, // HTTP/1.1, Connection: keep-alive
|
|||
false, // HTTP/1.1, Connection: close
|
|||
]; |
|||
var requests = 0; |
|||
var responses = 0; |
|||
|
|||
var server = net.createServer(function(socket) { |
|||
socket.write(SERVER_RESPONSES[requests]); |
|||
++requests; |
|||
}).listen(common.PORT, function() { |
|||
function makeRequest() { |
|||
var req = http.get({port: common.PORT}, function(res) { |
|||
assert.equal(req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], |
|||
SERVER_RESPONSES[responses] + ' should ' + |
|||
(SHOULD_KEEP_ALIVE[responses] ? '' : 'not ') + |
|||
'Keep-Alive'); |
|||
++responses; |
|||
if (responses < SHOULD_KEEP_ALIVE.length) { |
|||
makeRequest(); |
|||
} else { |
|||
server.close(); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
makeRequest(); |
|||
}); |
|||
|
|||
process.on('exit', function() { |
|||
assert.equal(requests, SERVER_RESPONSES.length); |
|||
assert.equal(responses, SHOULD_KEEP_ALIVE.length); |
|||
}); |
@ -0,0 +1,45 @@ |
|||
// 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.
|
|||
|
|||
if (!process.versions.openssl) { |
|||
console.error('Skipping because node compiled without OpenSSL.'); |
|||
process.exit(0); |
|||
} |
|||
|
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var tls = require('tls'); |
|||
|
|||
var errors = 0; |
|||
|
|||
var conn = tls.connect(common.PORT, function() { |
|||
assert(false); // callback should never be executed
|
|||
}); |
|||
conn.on('error', function() { |
|||
++errors; |
|||
assert.doesNotThrow(function() { |
|||
conn.destroy(); |
|||
}); |
|||
}); |
|||
|
|||
process.on('exit', function() { |
|||
assert.equal(errors, 1); |
|||
}); |
@ -0,0 +1,48 @@ |
|||
// 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'); |
|||
|
|||
// TODO: merge with test-typed-arrays.js some time in the future.
|
|||
// That file only exists in master right now.
|
|||
[ |
|||
'ArrayBuffer', |
|||
'Int8Array', |
|||
'Uint8Array', |
|||
'Int16Array', |
|||
'Uint16Array', |
|||
'Int32Array', |
|||
'Uint32Array', |
|||
'Float32Array', |
|||
'Float64Array' |
|||
].forEach(function(name) { |
|||
var expected = '[object ' + name + ']'; |
|||
var clazz = global[name]; |
|||
var obj = new clazz(1); |
|||
|
|||
assert.equal(obj.toString(), expected); |
|||
assert.equal(Object.prototype.toString.call(obj), expected); |
|||
|
|||
obj = new DataView(obj); |
|||
assert.equal(obj.toString(), '[object DataView]'); |
|||
assert.equal(Object.prototype.toString.call(obj), '[object DataView]'); |
|||
}); |
@ -0,0 +1,38 @@ |
|||
// 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.
|
|||
|
|||
// test uncompressing invalid input
|
|||
|
|||
var common = require('../common.js'), |
|||
assert = require('assert'), |
|||
zlib = require('zlib'); |
|||
|
|||
var nonStringInputs = [1, true, {a: 1}, ['a']]; |
|||
|
|||
nonStringInputs.forEach(function(input) { |
|||
// zlib.gunzip should not throw an error when called with bad input.
|
|||
assert.doesNotThrow(function () { |
|||
zlib.gunzip(input, function (err, buffer) { |
|||
// zlib.gunzip should pass the error to the callback.
|
|||
assert.ok(err); |
|||
}); |
|||
}); |
|||
}); |
Loading…
Reference in new issue