Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add setInterval and nextTick to domain test

  • Loading branch information...
commit 3ecb1534da0e0581d2d3dd70cf2508c67eb70544 1 parent ec2cfcd
@isaacs isaacs authored
Showing with 29 additions and 2 deletions.
  1. +29 −2 test/simple/test-domain.js
View
31 test/simple/test-domain.js
@@ -27,7 +27,7 @@ var assert = require('assert');
var domain = require('domain');
var events = require('events');
var caught = 0;
-var expectCaught = 7;
+var expectCaught = 8;
var d = new domain.Domain();
var e = new events.EventEmitter();
@@ -88,6 +88,12 @@ d.on('error', function(er) {
assert.ok(!er.domain_bound);
break;
+ case 'Cannot call method \'isDirectory\' of undefined':
+ assert.equal(er.domain, d);
+ assert.ok(!er.domain_emitter);
+ assert.ok(!er.domain_bound);
+ break;
+
default:
console.error('unexpected error, throwing %j', er.message);
throw er;
@@ -137,13 +143,34 @@ setTimeout(d.bind(thrower), 100);
// Pass an intercepted function to an fs operation that fails.
var fs = require('fs');
-fs.readFile('this file does not exist', d.intercept(function(er) {
+fs.open('this file does not exist', 'r', d.intercept(function(er) {
console.error('should not get here!', er);
throw new Error('should not get here!');
}, true));
+// catch thrown errors no matter how many times we enter the event loop
+// this only uses implicit binding, except for the first function
+// passed to d.run(). The rest are implicitly bound by virtue of being
+// set up while in the scope of the d domain.
+d.run(function() {
+ process.nextTick(function() {
+ var i = setInterval(function () {
+ clearInterval(i);
+ setTimeout(function() {
+ fs.stat('this file does not exist', function(er, stat) {
+ // uh oh! stat isn't set!
+ // pretty common error.
+ console.log(stat.isDirectory());
+ });
+ });
+ });
+ });
+});
+
+
+
// implicit addition by being created within a domain-bound context.
var implicit;

0 comments on commit 3ecb153

Please sign in to comment.
Something went wrong with that request. Please try again.