Sha256: 8fa8117eb0ec41411abc76e30c692fbcf4e6a65c3597e4acfd58aeca2b58a869

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

'use strict';

const common = require('../common');
const assert = require('assert');

// Make sure we test 0ms timers, since they would had always wanted to run on
// the current tick, and greater than 0ms timers, for scenarios where the
// outer timer takes longer to complete than the delay of the nested timer.
// Since the process of recreating this is identical regardless of the timer
// delay, these scenarios are in one test.
const scenarios = [0, 100];

scenarios.forEach(function(delay) {
  var nestedCalled = false;

  setTimeout(function A() {
    // Create the nested timer with the same delay as the outer timer so that it
    // gets added to the current list of timers being processed by
    // listOnTimeout.
    setTimeout(function B() {
      nestedCalled = true;
    }, delay);

    // Busy loop for the same timeout used for the nested timer to ensure that
    // we are in fact expiring the nested timer.
    common.busyLoop(delay);

    // The purpose of running this assert in nextTick is to make sure it runs
    // after A but before the next iteration of the libuv event loop.
    process.nextTick(function() {
      assert.ok(!nestedCalled);
    });

    // Ensure that the nested callback is indeed called prior to process exit.
    process.on('exit', function onExit() {
      assert.ok(nestedCalled);
    });
  }, delay);
});

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-timers-nested.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-timers-nested.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-timers-nested.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-timers-nested.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-timers-nested.js