Page MenuHomeWickedGov Phorge

ClockTest.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

ClockTest.php

<?php
namespace Wikimedia\Tests\Telemetry;
use MediaWikiUnitTestCase;
use Wikimedia\Telemetry\Clock;
/**
* @covers \Wikimedia\Telemetry\Clock
*/
class ClockTest extends MediaWikiUnitTestCase {
private Clock $clock;
protected function setUp(): void {
parent::setUp();
$this->clock = new Clock();
}
public function testShouldReturnCurrentTime(): void {
$this->assertClockReturnsCurrentTime();
}
public function testShouldAllowMockingTimestamp(): void {
Clock::setMockTime( 2_000 );
$this->assertSame( 2_000, $this->clock->getCurrentNanoTime() );
Clock::setMockTime( null );
$this->assertClockReturnsCurrentTime();
}
/**
* Utility function to assert that the Clock being tested returns the current time, with some leeway.
* @return void
*/
private function assertClockReturnsCurrentTime() {
$this->markTestSkipped( 'Flaky (T379562) - to be replaced by ConvertibleTimestamp::microtime()' );
$referenceTime = (int)( 1e9 * microtime( true ) ) - hrtime( true );
$currentTime = $referenceTime + hrtime( true );
usleep( 1 );
$now = $this->clock->getCurrentNanoTime();
usleep( 1 );
$afterTime = $referenceTime + hrtime( true );
$this->assertGreaterThan(
$currentTime,
$now,
'Too large time difference'
);
$this->assertLessThanOrEqual(
$afterTime,
$now,
'Too large time difference'
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Nov 22, 08:45 (17 h, 35 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
36/c6/be88460ae6de8c4f01aec8e3beea
Default Alt Text
ClockTest.php (1 KB)

Event Timeline