11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst timers = require('timers');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst OVERFLOW = Math.pow(2, 31); // TIMEOUT_MAX is 2^31-1
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_cifunction timerNotCanceled() {
101cb0ef41Sopenharmony_ci  assert.fail('Timer should be canceled');
111cb0ef41Sopenharmony_ci}
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciprocess.on('warning', common.mustCall((warning) => {
141cb0ef41Sopenharmony_ci  if (warning.name === 'DeprecationWarning') return;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  const lines = warning.message.split('\n');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  assert.strictEqual(warning.name, 'TimeoutOverflowWarning');
191cb0ef41Sopenharmony_ci  assert.strictEqual(lines[0], `${OVERFLOW} does not fit into a 32-bit signed` +
201cb0ef41Sopenharmony_ci                               ' integer.');
211cb0ef41Sopenharmony_ci  assert.strictEqual(lines.length, 2);
221cb0ef41Sopenharmony_ci}, 6));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci{
261cb0ef41Sopenharmony_ci  const timeout = setTimeout(timerNotCanceled, OVERFLOW);
271cb0ef41Sopenharmony_ci  clearTimeout(timeout);
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  const interval = setInterval(timerNotCanceled, OVERFLOW);
321cb0ef41Sopenharmony_ci  clearInterval(interval);
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci{
361cb0ef41Sopenharmony_ci  const timer = {
371cb0ef41Sopenharmony_ci    _onTimeout: timerNotCanceled
381cb0ef41Sopenharmony_ci  };
391cb0ef41Sopenharmony_ci  timers.enroll(timer, OVERFLOW);
401cb0ef41Sopenharmony_ci  timers.active(timer);
411cb0ef41Sopenharmony_ci  timers.unenroll(timer);
421cb0ef41Sopenharmony_ci}
43