Skip to content

Commit

Permalink
test: refactor make-callback-recurse test
Browse files Browse the repository at this point in the history
Move copy/pasted callback into its own function.

PR-URL: nodejs#9498
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
Trott committed Nov 10, 2016
1 parent ef6a5cf commit 837e822
Showing 1 changed file with 9 additions and 27 deletions.
36 changes: 9 additions & 27 deletions test/addons/make-callback-recurse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,38 +132,20 @@ function checkDomains() {
}));
}), 1);

// Make sure nextTick, setImmediate and setTimeout can all recover properly
// after a thrown makeCallback call.
process.nextTick(common.mustCall(function() {
function testTimer(id) {
// Make sure nextTick, setImmediate and setTimeout can all recover properly
// after a thrown makeCallback call.
const d = domain.create();
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() {
throw new Error('throw from domain 3');
throw new Error(`throw from domain ${id}`);
});
throw new Error('UNREACHABLE');
}));
}

setImmediate(common.mustCall(function() {
const d = domain.create();
d.on('error', common.mustCall(function(e) {
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');
}));
process.nextTick(common.mustCall(testTimer), 3);
setImmediate(common.mustCall(testTimer), 2);
setTimeout(common.mustCall(testTimer), 1, 1);
}

0 comments on commit 837e822

Please sign in to comment.