Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-timers.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df2240d2c444af659baef945e39b13f7d4ef3bcc (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const common = require('../common');
const assert = require('assert');

const inputs = [
  undefined,
  null,
  true,
  false,
  '',
  [],
  {},
  NaN,
  +Infinity,
  -Infinity,
  (1.0 / 0.0),      // sanity check
  parseFloat('x'),  // NaN
  -10,
  -1,
  -0.5,
  -0.1,
  -0.0,
  0,
  0.0,
  0.1,
  0.5,
  1,
  1.0,
  2147483648,     // browser behaviour: timeouts > 2^31-1 run on next tick
  12345678901234  // ditto
];

const timeouts = [];
const intervals = [];

inputs.forEach(function(value, index) {
  setTimeout(function() {
    timeouts[index] = true;
  }, value);

  const handle = setInterval(function() {
    clearInterval(handle); // disarm timer or we'll never finish
    intervals[index] = true;
  }, value);
});

// All values in inputs array coerce to 1 ms. Therefore, they should all run
// before a timer set here for 2 ms.

setTimeout(common.mustCall(function() {
  // assert that all other timers have run
  inputs.forEach(function(value, index) {
    assert(timeouts[index]);
    assert(intervals[index]);
  });
}), 2);

// Test 10 ms timeout separately.
setTimeout(common.mustCall(function() {}), 10);
setInterval(common.mustCall(function() { clearInterval(this); }), 10);