Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7427019
ClockTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ClockTest.php
View Options
<?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
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 08:45 (17 h, 41 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
36/c6/be88460ae6de8c4f01aec8e3beea
Default Alt Text
ClockTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment