11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst active = require('timers').active;
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// active() should create timers for these
71cb0ef41Sopenharmony_ciconst legitTimers = [
81cb0ef41Sopenharmony_ci  { _idleTimeout: 0 },
91cb0ef41Sopenharmony_ci  { _idleTimeout: 1 },
101cb0ef41Sopenharmony_ci];
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cilegitTimers.forEach(function(legit) {
131cb0ef41Sopenharmony_ci  const savedTimeout = legit._idleTimeout;
141cb0ef41Sopenharmony_ci  active(legit);
151cb0ef41Sopenharmony_ci  // active() should mutate these objects
161cb0ef41Sopenharmony_ci  assert.strictEqual(legit._idleTimeout, savedTimeout);
171cb0ef41Sopenharmony_ci  assert(Number.isInteger(legit._idleStart));
181cb0ef41Sopenharmony_ci  assert(legit._idleNext);
191cb0ef41Sopenharmony_ci  assert(legit._idlePrev);
201cb0ef41Sopenharmony_ci});
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci// active() should not create a timer for these
241cb0ef41Sopenharmony_ciconst bogusTimers = [
251cb0ef41Sopenharmony_ci  { _idleTimeout: -1 },
261cb0ef41Sopenharmony_ci  { _idleTimeout: undefined },
271cb0ef41Sopenharmony_ci];
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cibogusTimers.forEach(function(bogus) {
301cb0ef41Sopenharmony_ci  const savedTimeout = bogus._idleTimeout;
311cb0ef41Sopenharmony_ci  active(bogus);
321cb0ef41Sopenharmony_ci  // active() should not mutate these objects
331cb0ef41Sopenharmony_ci  assert.deepStrictEqual(bogus, { _idleTimeout: savedTimeout });
341cb0ef41Sopenharmony_ci});
35