Browse Source

test: refactor make-callback-recurse test

Move copy/pasted callback into its own function.

PR-URL: https://github.com/nodejs/node/pull/9498
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v6
Rich Trott 8 years ago
parent
commit
837e822992
  1. 36
      test/addons/make-callback-recurse/test.js

36
test/addons/make-callback-recurse/test.js

@ -132,38 +132,20 @@ function checkDomains() {
})); }));
}), 1); }), 1);
// Make sure nextTick, setImmediate and setTimeout can all recover properly function testTimer(id) {
// after a thrown makeCallback call. // Make sure nextTick, setImmediate and setTimeout can all recover properly
process.nextTick(common.mustCall(function() { // after a thrown makeCallback call.
const d = domain.create(); const d = domain.create();
d.on('error', common.mustCall(function(e) { d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, 'throw from domain 3'); assert.strictEqual(e.message, `throw from domain ${id}`);
})); }));
makeCallback({domain: d}, function() { makeCallback({domain: d}, function() {
throw new Error('throw from domain 3'); throw new Error(`throw from domain ${id}`);
}); });
throw new Error('UNREACHABLE'); throw new Error('UNREACHABLE');
})); }
setImmediate(common.mustCall(function() { process.nextTick(common.mustCall(testTimer), 3);
const d = domain.create(); setImmediate(common.mustCall(testTimer), 2);
d.on('error', common.mustCall(function(e) { setTimeout(common.mustCall(testTimer), 1, 1);
assert.strictEqual(e.message, 'throw from domain 2');
}));
makeCallback({domain: d}, function() {
throw new Error('throw from domain 2');
});
throw new Error('UNREACHABLE');
}));
setTimeout(common.mustCall(function() {
const d = domain.create();
d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, 'throw from domain 1');
}));
makeCallback({domain: d}, function() {
throw new Error('throw from domain 1');
});
throw new Error('UNREACHABLE');
}));
} }

Loading…
Cancel
Save