1'use strict'; 2const common = require('../common'); 3 4// This test ensures that the timer callbacks are called in the order in which 5// they were created in the event of an unhandled exception in the domain. 6 7const domain = require('domain').create(); 8const assert = require('assert'); 9 10let first = false; 11 12domain.run(function() { 13 setTimeout(() => { throw new Error('FAIL'); }, 1); 14 setTimeout(() => { first = true; }, 1); 15 setTimeout(() => { assert.strictEqual(first, true); }, 2); 16 17 // Ensure that 2 ms have really passed 18 let i = 1e6; 19 while (i--); 20}); 21 22domain.once('error', common.mustCall((err) => { 23 assert(err); 24 assert.strictEqual(err.message, 'FAIL'); 25})); 26