function TimerUnitTest::testTimer

Tests timer_read() time accumulation accuracy across multiple restarts.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Bootstrap/TimerUnitTest.php, line 28
Definition of Drupal\system\Tests\Bootstrap\TimerUnitTest.

Class

TimerUnitTest
Tests timer_read().

Namespace

Drupal\system\Tests\Bootstrap

Code

function testTimer() {
  timer_start('test');
  sleep(1);
  $this
    ->assertTrue(timer_read('test') >= 1000, 'Timer measured 1 second of sleeping while running.');
  sleep(1);
  timer_stop('test');
  $this
    ->assertTrue(timer_read('test') >= 2000, 'Timer measured 2 seconds of sleeping after being stopped.');
  timer_start('test');
  sleep(1);
  $this
    ->assertTrue(timer_read('test') >= 3000, 'Timer measured 3 seconds of sleeping after being restarted.');
  sleep(1);
  $timer = timer_stop('test');
  $this
    ->assertTrue(timer_read('test') >= 4000, 'Timer measured 4 seconds of sleeping after being stopped for a second time.');
  $this
    ->assertEqual($timer['count'], 2, 'Timer counted 2 instances of being started.');
}