summaryrefslogtreecommitdiff
path: root/test/parallel/test-domain-timers.js
blob: 5a34bc7449a951b5ccef4a53880f735af868695e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var domain = require('domain');
var assert = require('assert');
var common = require('../common');

var timeout_err, timeout, immediate_err;

var timeoutd = domain.create();

timeoutd.on('error', function(e) {
  timeout_err = e;
  clearTimeout(timeout);
});

timeoutd.run(function() {
  setTimeout(function() {
    throw new Error('Timeout UNREFd');
  }).unref();
});

var immediated = domain.create();

immediated.on('error', function(e) {
  immediate_err = e;
});

immediated.run(function() {
  setImmediate(function() {
    throw new Error('Immediate Error');
  });
});

timeout = setTimeout(function() {}, 10 * 1000);

process.on('exit', function() {
  assert.equal(timeout_err.message, 'Timeout UNREFd',
      'Domain should catch timer error');
  assert.equal(immediate_err.message, 'Immediate Error',
      'Domain should catch immediate error');
});