mirror of https://github.com/lukechilds/node.git
Browse Source
Async Listener was the name of the user-facing JS API, and is being completely removed. Instead low level hooks directly into the mechanism that AL used will be introduced in a future commit. PR-URL: https://github.com/joyent/node/pull/8110 Signed-off-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Fedor Indutny <fedor@indutny.com> Reviewed-by: Alexis Campailla <alexis@janeasystems.com> Reviewed-by: Julien Gilli <julien.gilli@joyent.com>archived-io.js-v0.12
Trevor Norris
10 years ago
committed by
Bert Belder
28 changed files with 8 additions and 2371 deletions
@ -1,76 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var active = null; |
|
||||
var cntr = 0; |
|
||||
|
|
||||
function onAsync0() { |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
function onAsync1() { |
|
||||
return 1; |
|
||||
} |
|
||||
|
|
||||
function onError(stor) { |
|
||||
results.push(stor); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
var results = []; |
|
||||
var asyncNoHandleError0 = { |
|
||||
create: onAsync0, |
|
||||
error: onError |
|
||||
}; |
|
||||
var asyncNoHandleError1 = { |
|
||||
create: onAsync1, |
|
||||
error: onError |
|
||||
}; |
|
||||
|
|
||||
var listeners = [ |
|
||||
tracing.addAsyncListener(asyncNoHandleError0), |
|
||||
tracing.addAsyncListener(asyncNoHandleError1) |
|
||||
]; |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
throw new Error(); |
|
||||
}); |
|
||||
|
|
||||
tracing.removeAsyncListener(listeners[0]); |
|
||||
tracing.removeAsyncListener(listeners[1]); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// Handling of errors should propagate to all listeners.
|
|
||||
assert.equal(results[0], 0); |
|
||||
assert.equal(results[1], 1); |
|
||||
assert.equal(results.length, 2); |
|
||||
|
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,65 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var results = []; |
|
||||
var asyncNoHandleError = { |
|
||||
error: function(stor) { |
|
||||
results.push(1); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var asyncHandleError = { |
|
||||
error: function(stor) { |
|
||||
results.push(0); |
|
||||
return true; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listeners = [ |
|
||||
tracing.addAsyncListener(asyncHandleError), |
|
||||
tracing.addAsyncListener(asyncNoHandleError) |
|
||||
]; |
|
||||
|
|
||||
// Even if an error handler returns true, both should fire.
|
|
||||
process.nextTick(function() { |
|
||||
throw new Error(); |
|
||||
}); |
|
||||
|
|
||||
tracing.removeAsyncListener(listeners[0]); |
|
||||
tracing.removeAsyncListener(listeners[1]); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// Mixed handling of errors should propagate to all listeners.
|
|
||||
assert.equal(results[0], 0); |
|
||||
assert.equal(results[1], 1); |
|
||||
assert.equal(results.length, 2); |
|
||||
|
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,79 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
function onAsync0() { |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
function onAsync1() { |
|
||||
return 1; |
|
||||
} |
|
||||
|
|
||||
function onError(stor) { |
|
||||
results.push(stor); |
|
||||
} |
|
||||
|
|
||||
var results = []; |
|
||||
var asyncNoHandleError0 = { |
|
||||
create: onAsync0, |
|
||||
error: onError |
|
||||
}; |
|
||||
var asyncNoHandleError1 = { |
|
||||
create: onAsync1, |
|
||||
error: onError |
|
||||
}; |
|
||||
|
|
||||
var listeners = [ |
|
||||
tracing.addAsyncListener(asyncNoHandleError0), |
|
||||
tracing.addAsyncListener(asyncNoHandleError1) |
|
||||
]; |
|
||||
|
|
||||
var uncaughtFired = false; |
|
||||
process.on('uncaughtException', function() { |
|
||||
uncaughtFired = true; |
|
||||
|
|
||||
// Unhandled errors should propagate to all listeners.
|
|
||||
assert.equal(results[0], 0); |
|
||||
assert.equal(results[1], 1); |
|
||||
assert.equal(results.length, 2); |
|
||||
}); |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
throw new Error(); |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// Need to remove the async listeners or tests will always pass
|
|
||||
for (var i = 0; i < listeners.length; i++) |
|
||||
tracing.removeAsyncListener(listeners[i]); |
|
||||
|
|
||||
assert.ok(uncaughtFired); |
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,108 +0,0 @@ |
|||||
// 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 dns = require('dns'); |
|
||||
var fs = require('fs'); |
|
||||
var net = require('net'); |
|
||||
var tracing = require('tracing'); |
|
||||
|
|
||||
var errorMsgs = []; |
|
||||
var caught = 0; |
|
||||
var expectCaught = 0; |
|
||||
|
|
||||
var callbacksObj = { |
|
||||
error: function(value, er) { |
|
||||
var idx = errorMsgs.indexOf(er.message); |
|
||||
caught++; |
|
||||
|
|
||||
process._rawDebug('Handling error: ' + er.message); |
|
||||
|
|
||||
if (-1 < idx) |
|
||||
errorMsgs.splice(idx, 1); |
|
||||
else |
|
||||
throw new Error('Message not found: ' + er.message); |
|
||||
|
|
||||
return true; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.addAsyncListener(callbacksObj); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
tracing.removeAsyncListener(listener); |
|
||||
|
|
||||
if (code > 0) |
|
||||
return; |
|
||||
|
|
||||
if (errorMsgs.length > 0) |
|
||||
throw new Error('Errors not fired: ' + errorMsgs); |
|
||||
|
|
||||
assert.equal(caught, expectCaught); |
|
||||
process._rawDebug('ok'); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Net
|
|
||||
var iter = 3; |
|
||||
for (var i = 0; i < iter; i++) { |
|
||||
errorMsgs.push('net - error: server connection'); |
|
||||
errorMsgs.push('net - error: client data'); |
|
||||
errorMsgs.push('net - error: server data'); |
|
||||
} |
|
||||
errorMsgs.push('net - error: server closed'); |
|
||||
|
|
||||
var server = net.createServer(function(c) { |
|
||||
c.on('data', function() { |
|
||||
if (0 === --iter) { |
|
||||
server.close(function() { |
|
||||
process._rawDebug('net - server closing'); |
|
||||
throw new Error('net - error: server closed'); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
} |
|
||||
process._rawDebug('net - connection received data'); |
|
||||
throw new Error('net - error: server data'); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
c.end('bye'); |
|
||||
process._rawDebug('net - connection received'); |
|
||||
throw new Error('net - error: server connection'); |
|
||||
}); |
|
||||
expectCaught += iter; |
|
||||
|
|
||||
server.listen(common.PORT, function() { |
|
||||
for (var i = 0; i < iter; i++) |
|
||||
clientConnect(); |
|
||||
}); |
|
||||
|
|
||||
function clientConnect() { |
|
||||
var client = net.connect(common.PORT, function() { }); |
|
||||
|
|
||||
client.on('data', function() { |
|
||||
client.end('see ya'); |
|
||||
process._rawDebug('net - client received data'); |
|
||||
throw new Error('net - error: client data'); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
} |
|
@ -1,62 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var once = 0; |
|
||||
|
|
||||
var results = []; |
|
||||
var handlers = { |
|
||||
after: function() { |
|
||||
throw 1; |
|
||||
}, |
|
||||
error: function(stor, err) { |
|
||||
// Error handler must be called exactly *once*.
|
|
||||
once++; |
|
||||
assert.equal(err, 1); |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var key = tracing.addAsyncListener(handlers); |
|
||||
|
|
||||
var uncaughtFired = false; |
|
||||
process.on('uncaughtException', function(err) { |
|
||||
uncaughtFired = true; |
|
||||
|
|
||||
assert.equal(once, 1); |
|
||||
}); |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
|
|
||||
tracing.removeAsyncListener(key); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
assert.ok(uncaughtFired); |
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,80 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var once = 0; |
|
||||
|
|
||||
var results = []; |
|
||||
var handlers = { |
|
||||
before: function() { |
|
||||
throw 1; |
|
||||
}, |
|
||||
error: function(stor, err) { |
|
||||
// Must catch error thrown in before callback.
|
|
||||
assert.equal(err, 1); |
|
||||
once++; |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var handlers1 = { |
|
||||
before: function() { |
|
||||
throw 2; |
|
||||
}, |
|
||||
error: function(stor, err) { |
|
||||
// Must catch *other* handlers throw by error callback.
|
|
||||
assert.equal(err, 1); |
|
||||
once++; |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var listeners = [ |
|
||||
tracing.addAsyncListener(handlers), |
|
||||
tracing.addAsyncListener(handlers1) |
|
||||
]; |
|
||||
|
|
||||
var uncaughtFired = false; |
|
||||
process.on('uncaughtException', function(err) { |
|
||||
uncaughtFired = true; |
|
||||
|
|
||||
// Both error handlers must fire.
|
|
||||
assert.equal(once, 2); |
|
||||
}); |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
|
|
||||
for (var i = 0; i < listeners.length; i++) |
|
||||
tracing.removeAsyncListener(listeners[i]); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
// Make sure uncaughtException actually fired.
|
|
||||
assert.ok(uncaughtFired); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
@ -1,64 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var once = 0; |
|
||||
|
|
||||
var results = []; |
|
||||
var handlers = { |
|
||||
before: function() { |
|
||||
throw 1; |
|
||||
}, |
|
||||
error: function(stor, err) { |
|
||||
// Error handler must be called exactly *once*.
|
|
||||
once++; |
|
||||
assert.equal(err, 1); |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var key = tracing.addAsyncListener(handlers); |
|
||||
|
|
||||
var uncaughtFired = false; |
|
||||
process.on('uncaughtException', function(err) { |
|
||||
uncaughtFired = true; |
|
||||
|
|
||||
// Process should propagate error regardless of handlers return value.
|
|
||||
assert.equal(once, 1); |
|
||||
}); |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
|
|
||||
tracing.removeAsyncListener(key); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// Make sure that the uncaughtException actually fired.
|
|
||||
assert.ok(uncaughtFired); |
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,87 +0,0 @@ |
|||||
// 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 spawn = require('child_process').spawn; |
|
||||
var tracing = require('tracing'); |
|
||||
|
|
||||
var checkStr = 'WRITTEN ON EXIT'; |
|
||||
|
|
||||
if (process.argv[2] === 'child') |
|
||||
runChild(); |
|
||||
else |
|
||||
runParent(); |
|
||||
|
|
||||
|
|
||||
function runChild() { |
|
||||
var cntr = 0; |
|
||||
|
|
||||
var key = tracing.addAsyncListener({ |
|
||||
error: function onError() { |
|
||||
cntr++; |
|
||||
throw new Error('onError'); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
process.on('unhandledException', function() { |
|
||||
// Throwing in 'error' should bypass unhandledException.
|
|
||||
process.exit(2); |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
// Make sure that we can still write out to stderr even when the
|
|
||||
// process dies.
|
|
||||
process._rawDebug(checkStr); |
|
||||
}); |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
throw new Error('nextTick'); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
function runParent() { |
|
||||
var childDidExit = false; |
|
||||
var childStr = ''; |
|
||||
var child = spawn(process.execPath, [__filename, 'child']); |
|
||||
child.stderr.on('data', function(chunk) { |
|
||||
process._rawDebug('received data from child'); |
|
||||
childStr += chunk.toString(); |
|
||||
}); |
|
||||
|
|
||||
child.on('exit', function(code) { |
|
||||
process._rawDebug('child process exiting'); |
|
||||
childDidExit = true; |
|
||||
// This is thrown when Node throws from _fatalException.
|
|
||||
assert.equal(code, 7); |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
process._rawDebug('child ondata message:', |
|
||||
childStr.substr(0, checkStr.length)); |
|
||||
|
|
||||
assert.ok(childDidExit); |
|
||||
assert.equal(childStr.substr(0, checkStr.length), checkStr); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
} |
|
||||
|
|
@ -1,257 +0,0 @@ |
|||||
// 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 dns = require('dns'); |
|
||||
var fs = require('fs'); |
|
||||
var net = require('net'); |
|
||||
var tracing = require('tracing'); |
|
||||
|
|
||||
var addListener = tracing.addAsyncListener; |
|
||||
var removeListener = tracing.removeAsyncListener; |
|
||||
var errorMsgs = []; |
|
||||
var currentMsg = ''; |
|
||||
var caught = 0; |
|
||||
var expectCaught = 0; |
|
||||
var exitCbRan = false; |
|
||||
|
|
||||
var callbacksObj = { |
|
||||
error: function(value, er) { |
|
||||
var idx = errorMsgs.indexOf(er.message); |
|
||||
|
|
||||
caught++; |
|
||||
|
|
||||
if (-1 < idx) |
|
||||
errorMsgs.splice(idx, 1); |
|
||||
|
|
||||
return currentMsg === er.message; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.createAsyncListener(callbacksObj); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
removeListener(listener); |
|
||||
|
|
||||
// Something else went wrong, no need to further check.
|
|
||||
if (code > 0) |
|
||||
return; |
|
||||
|
|
||||
// Make sure the exit callback only runs once.
|
|
||||
assert.ok(!exitCbRan); |
|
||||
exitCbRan = true; |
|
||||
|
|
||||
// Check if any error messages weren't removed from the msg queue.
|
|
||||
if (errorMsgs.length > 0) |
|
||||
throw new Error('Errors not fired: ' + errorMsgs); |
|
||||
|
|
||||
assert.equal(caught, expectCaught, 'caught all expected errors'); |
|
||||
process._rawDebug('ok'); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Catch synchronous throws
|
|
||||
errorMsgs.push('sync throw'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
expectCaught++; |
|
||||
currentMsg = 'sync throw'; |
|
||||
throw new Error(currentMsg); |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Simple cases
|
|
||||
errorMsgs.push('setTimeout - simple'); |
|
||||
errorMsgs.push('setImmediate - simple'); |
|
||||
errorMsgs.push('setInterval - simple'); |
|
||||
errorMsgs.push('process.nextTick - simple'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
setTimeout(function() { |
|
||||
currentMsg = 'setTimeout - simple'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
setImmediate(function() { |
|
||||
currentMsg = 'setImmediate - simple'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
var b = setInterval(function() { |
|
||||
clearInterval(b); |
|
||||
currentMsg = 'setInterval - simple'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
currentMsg = 'process.nextTick - simple'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Deeply nested
|
|
||||
errorMsgs.push('setInterval - nested'); |
|
||||
errorMsgs.push('setImmediate - nested'); |
|
||||
errorMsgs.push('process.nextTick - nested'); |
|
||||
errorMsgs.push('setTimeout2 - nested'); |
|
||||
errorMsgs.push('setTimeout - nested'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
setTimeout(function() { |
|
||||
process.nextTick(function() { |
|
||||
setImmediate(function() { |
|
||||
var b = setInterval(function() { |
|
||||
clearInterval(b); |
|
||||
currentMsg = 'setInterval - nested'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
currentMsg = 'setImmediate - nested'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
currentMsg = 'process.nextTick - nested'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
setTimeout(function() { |
|
||||
currentMsg = 'setTimeout2 - nested'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
currentMsg = 'setTimeout - nested'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// FS
|
|
||||
errorMsgs.push('fs - file does not exist'); |
|
||||
errorMsgs.push('fs - exists'); |
|
||||
errorMsgs.push('fs - realpath'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
fs.stat('does not exist', function(err, stats) { |
|
||||
currentMsg = 'fs - file does not exist'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
fs.exists('hi all', function(exists) { |
|
||||
currentMsg = 'fs - exists'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
fs.realpath('/some/path', function(err, resolved) { |
|
||||
currentMsg = 'fs - realpath'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Nested FS
|
|
||||
errorMsgs.push('fs - nested file does not exist'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
setTimeout(function() { |
|
||||
setImmediate(function() { |
|
||||
var b = setInterval(function() { |
|
||||
clearInterval(b); |
|
||||
process.nextTick(function() { |
|
||||
fs.stat('does not exist', function(err, stats) { |
|
||||
currentMsg = 'fs - nested file does not exist'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Net
|
|
||||
errorMsgs.push('net - connection listener'); |
|
||||
errorMsgs.push('net - client connect'); |
|
||||
errorMsgs.push('net - server listening'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
var server = net.createServer(function(c) { |
|
||||
server.close(); |
|
||||
currentMsg = 'net - connection listener'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
server.listen(common.PORT, function() { |
|
||||
var client = net.connect(common.PORT, function() { |
|
||||
client.end(); |
|
||||
currentMsg = 'net - client connect'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
currentMsg = 'net - server listening'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// DNS
|
|
||||
errorMsgs.push('dns - lookup'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
dns.lookup('localhost', function() { |
|
||||
currentMsg = 'dns - lookup'; |
|
||||
throw new Error(currentMsg); |
|
||||
}); |
|
||||
expectCaught++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
@ -1,70 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var addListener = tracing.addAsyncListener; |
|
||||
var removeListener = tracing.removeAsyncListener; |
|
||||
var caught = []; |
|
||||
var expect = []; |
|
||||
|
|
||||
var callbacksObj = { |
|
||||
error: function(value, er) { |
|
||||
process._rawDebug('caught', er.message); |
|
||||
caught.push(er.message); |
|
||||
return (expect.indexOf(er.message) !== -1); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.createAsyncListener(callbacksObj); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
removeListener(listener); |
|
||||
|
|
||||
if (code > 0) |
|
||||
return; |
|
||||
|
|
||||
expect = expect.sort(); |
|
||||
caught = caught.sort(); |
|
||||
|
|
||||
process._rawDebug('expect', expect); |
|
||||
process._rawDebug('caught', caught); |
|
||||
assert.deepEqual(caught, expect, 'caught all expected errors'); |
|
||||
process._rawDebug('ok'); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
expect.push('immediate simple a'); |
|
||||
expect.push('immediate simple b'); |
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
// Tests for a setImmediate specific bug encountered while implementing
|
|
||||
// AsyncListeners.
|
|
||||
setImmediate(function() { |
|
||||
throw new Error('immediate simple a'); |
|
||||
}); |
|
||||
setImmediate(function() { |
|
||||
throw new Error('immediate simple b'); |
|
||||
}); |
|
||||
removeListener(listener); |
|
||||
}); |
|
@ -1,47 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
var val; |
|
||||
var callbacks = { |
|
||||
create: function() { |
|
||||
return 42; |
|
||||
}, |
|
||||
before: function() { |
|
||||
tracing.removeAsyncListener(listener); |
|
||||
tracing.addAsyncListener(listener); |
|
||||
}, |
|
||||
after: function(context, storage) { |
|
||||
val = storage; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.addAsyncListener(callbacks); |
|
||||
|
|
||||
process.nextTick(function() {}); |
|
||||
|
|
||||
process.on('exit', function(status) { |
|
||||
tracing.removeAsyncListener(listener); |
|
||||
assert.equal(status, 0); |
|
||||
assert.equal(val, 42); |
|
||||
}); |
|
@ -1,53 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
var set = 0; |
|
||||
|
|
||||
var asyncNoHandleError = { |
|
||||
before: function() { |
|
||||
set++; |
|
||||
}, |
|
||||
after: function() { |
|
||||
set++; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var key = tracing.addAsyncListener(asyncNoHandleError); |
|
||||
|
|
||||
tracing.removeAsyncListener(key); |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// The async handler should never be called.
|
|
||||
assert.equal(set, 0); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
||||
|
|
@ -1,43 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
var done = false; |
|
||||
var callbacks = { |
|
||||
before: function() { |
|
||||
tracing.removeAsyncListener(listener); |
|
||||
}, |
|
||||
after: function() { |
|
||||
done = true; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.addAsyncListener(callbacks); |
|
||||
|
|
||||
process.nextTick(function() {}); |
|
||||
|
|
||||
process.on('exit', function(status) { |
|
||||
tracing.removeAsyncListener(listener); |
|
||||
assert.equal(status, 0); |
|
||||
assert.ok(done); |
|
||||
}); |
|
@ -1,58 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var set = 0; |
|
||||
var asyncNoHandleError = { |
|
||||
error: function() { |
|
||||
set++; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var key = tracing.addAsyncListener(asyncNoHandleError); |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
throw 1; |
|
||||
}); |
|
||||
|
|
||||
tracing.removeAsyncListener(key); |
|
||||
|
|
||||
var uncaughtFired = false; |
|
||||
process.on('uncaughtException', function() { |
|
||||
uncaughtFired = true; |
|
||||
|
|
||||
// Throwing should call the error handler once, then propagate to
|
|
||||
// uncaughtException
|
|
||||
assert.equal(set, 1); |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
assert.ok(uncaughtFired); |
|
||||
console.log('ok'); |
|
||||
}); |
|
@ -1,53 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var set = 0; |
|
||||
var asyncNoHandleError = { |
|
||||
before: function() { |
|
||||
set++; |
|
||||
}, |
|
||||
after: function() { |
|
||||
set++; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var key = tracing.addAsyncListener(asyncNoHandleError); |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
|
|
||||
tracing.removeAsyncListener(key); |
|
||||
|
|
||||
process.on('exit', function(code) { |
|
||||
// If the exit code isn't ok then return early to throw the stack that
|
|
||||
// caused the bad return code.
|
|
||||
if (code !== 0) |
|
||||
return; |
|
||||
|
|
||||
// Calling removeAsyncListener *after* a callback is scheduled
|
|
||||
// should not affect the handler from responding to the callback.
|
|
||||
assert.equal(set, 2); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
@ -1,59 +0,0 @@ |
|||||
// 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 net = require('net'); |
|
||||
var tracing = require('tracing'); |
|
||||
|
|
||||
var errMsg = 'net - error: server connection'; |
|
||||
var cntr = 0; |
|
||||
var al = tracing.addAsyncListener({ |
|
||||
error: function(stor, er) { |
|
||||
cntr++; |
|
||||
process._rawDebug('Handling error: ' + er.message); |
|
||||
assert.equal(errMsg, er.message); |
|
||||
return true; |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function(status) { |
|
||||
tracing.removeAsyncListener(al); |
|
||||
|
|
||||
console.log('exit status:', status); |
|
||||
assert.equal(status, 0); |
|
||||
console.log('cntr:', cntr); |
|
||||
assert.equal(cntr, 1); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
var server = net.createServer(function(c) { |
|
||||
this.close(); |
|
||||
throw new Error(errMsg); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
server.listen(common.PORT, function() { |
|
||||
net.connect(common.PORT, function() { |
|
||||
this.destroy(); |
|
||||
}); |
|
||||
}); |
|
@ -1,46 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
var cntr = 0; |
|
||||
var al = tracing.createAsyncListener({ |
|
||||
create: function() { cntr++; }, |
|
||||
}); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
assert.equal(cntr, 4); |
|
||||
console.log('ok'); |
|
||||
}); |
|
||||
|
|
||||
tracing.addAsyncListener(al); |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
tracing.addAsyncListener(al); |
|
||||
process.nextTick(function() { |
|
||||
tracing.addAsyncListener(al); |
|
||||
process.nextTick(function() { |
|
||||
process.nextTick(function() { }); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
@ -1,48 +0,0 @@ |
|||||
// 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 tracing = require('tracing'); |
|
||||
|
|
||||
// If there is an uncaughtException listener then the error thrown from
|
|
||||
// "before" will be considered handled, thus calling setImmediate to
|
|
||||
// finish execution of the nextTickQueue. This in turn will cause "before"
|
|
||||
// to fire again, entering into an infinite loop.
|
|
||||
// So the asyncQueue is cleared from the returned setImmediate in
|
|
||||
// _fatalException to prevent this from happening.
|
|
||||
var cntr = 0; |
|
||||
|
|
||||
|
|
||||
tracing.addAsyncListener({ |
|
||||
before: function() { |
|
||||
if (++cntr > 1) { |
|
||||
// Can't throw since uncaughtException will also catch that.
|
|
||||
process._rawDebug('Error: Multiple before callbacks called'); |
|
||||
process.exit(1); |
|
||||
} |
|
||||
throw new Error('before'); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
process.on('uncaughtException', function() { }); |
|
||||
|
|
||||
process.nextTick(); |
|
@ -1,188 +0,0 @@ |
|||||
// 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 net = require('net'); |
|
||||
var fs = require('fs'); |
|
||||
var dgram = require('dgram'); |
|
||||
var tracing = require('tracing'); |
|
||||
|
|
||||
var addListener = tracing.addAsyncListener; |
|
||||
var removeListener = tracing.removeAsyncListener; |
|
||||
var actualAsync = 0; |
|
||||
var expectAsync = 0; |
|
||||
|
|
||||
var callbacks = { |
|
||||
create: function onAsync() { |
|
||||
actualAsync++; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
var listener = tracing.createAsyncListener(callbacks); |
|
||||
|
|
||||
process.on('exit', function() { |
|
||||
process._rawDebug('expected', expectAsync); |
|
||||
process._rawDebug('actual ', actualAsync); |
|
||||
// TODO(trevnorris): Not a great test. If one was missed, but others
|
|
||||
// overflowed then the test would still pass.
|
|
||||
assert.ok(actualAsync >= expectAsync); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Test listeners side-by-side
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
var b = setInterval(function() { |
|
||||
clearInterval(b); |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
|
|
||||
var c = setInterval(function() { |
|
||||
clearInterval(c); |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setTimeout(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setTimeout(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
process.nextTick(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setImmediate(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setImmediate(function() { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setTimeout(function() { }, 10); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setTimeout(function() { }, 10); |
|
||||
expectAsync++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Async listeners should propagate with nested callbacks
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
var interval = 3; |
|
||||
|
|
||||
process.nextTick(function() { |
|
||||
setTimeout(function() { |
|
||||
setImmediate(function() { |
|
||||
var i = setInterval(function() { |
|
||||
if (--interval <= 0) |
|
||||
clearInterval(i); |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
process.nextTick(function() { |
|
||||
setImmediate(function() { |
|
||||
setTimeout(function() { }, 20); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Test triggers with two async listeners
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
addListener(listener); |
|
||||
|
|
||||
setTimeout(function() { |
|
||||
process.nextTick(function() { }); |
|
||||
expectAsync += 2; |
|
||||
}); |
|
||||
expectAsync += 2; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Test callbacks from fs I/O
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
fs.stat('something random', function(err, stat) { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
setImmediate(function() { |
|
||||
fs.stat('random again', function(err, stat) { }); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Test net I/O
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
var server = net.createServer(function(c) { }); |
|
||||
expectAsync++; |
|
||||
|
|
||||
server.listen(common.PORT, function() { |
|
||||
server.close(); |
|
||||
expectAsync++; |
|
||||
}); |
|
||||
expectAsync++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
// Test UDP
|
|
||||
process.nextTick(function() { |
|
||||
addListener(listener); |
|
||||
|
|
||||
var server = dgram.createSocket('udp4'); |
|
||||
expectAsync++; |
|
||||
|
|
||||
server.bind(common.PORT); |
|
||||
|
|
||||
server.close(); |
|
||||
expectAsync++; |
|
||||
|
|
||||
removeListener(listener); |
|
||||
}); |
|
Loading…
Reference in new issue