11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { sleep } = require('internal/util'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cilet cntr = 0; 81cb0ef41Sopenharmony_cilet first; 91cb0ef41Sopenharmony_ciconst t = setInterval(() => { 101cb0ef41Sopenharmony_ci cntr++; 111cb0ef41Sopenharmony_ci if (cntr === 1) { 121cb0ef41Sopenharmony_ci sleep(100); 131cb0ef41Sopenharmony_ci // Ensure that the event loop passes before the second interval 141cb0ef41Sopenharmony_ci setImmediate(() => assert.strictEqual(cntr, 1)); 151cb0ef41Sopenharmony_ci first = Date.now(); 161cb0ef41Sopenharmony_ci } else if (cntr === 2) { 171cb0ef41Sopenharmony_ci assert(Date.now() - first < 100); 181cb0ef41Sopenharmony_ci clearInterval(t); 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci}, 100); 211cb0ef41Sopenharmony_ciconst t2 = setInterval(() => { 221cb0ef41Sopenharmony_ci if (cntr === 2) { 231cb0ef41Sopenharmony_ci clearInterval(t2); 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci}, 100); 26