8000 test ci · divinity76/php-src@3e77d3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e77d3b

Browse files
authored
test ci
1 parent 43ddd46 commit 3e77d3b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

ext/standard/tests/misc/time_sleep_until_basic.phpt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ Michele Orselli mo@ideato.it
2020
*
2121
* @return bool True if the absolute difference is less than or equal to the tolerance, false otherwise.
2222
*/
23-
function isWithinTolerance(float $val, float $target, float $tolerance): bool {
23+
function isWithinTolerance(float $val, float $target, float $tolerance): bool
24+
{
2425
return abs($val - $target) <= $tolerance;
2526
}
2627

28+
$startTime = microtime(true);
2729
// Calculate the target sleep time (2 seconds from now)
28-
$targetTime = microtime(true) + 2;
29-
$sleepUntil = $targetTime;
30-
31-
// Sleep until the target time and output the result of time_sleep_until()
32-
var_dump(time_sleep_until($sleepUntil));
33-
30+
$targetTime = $startTime + 2;
31+
// Sleep until the target time
32+
$dump = time_sleep_until($targetTime);
3433
// Capture the current time immediately after sleep
35-
$currentTime = microtime(true);
34+
$timeAfterSleep = microtime(true);
35+
var_dump($dump);
3636
if (stripos(PHP_OS, 'WIN') === 0) {
3737
// on windows, time_sleep_until has millisecond accuracy while microtime() is accurate
3838
// to 10th of a second. this means there can be up to a .9 millisecond difference
@@ -45,18 +45,24 @@ if (stripos(PHP_OS, 'WIN') === 0) {
4545
$tolerance = 0.05;
4646
} elseif (stripos(PHP_OS, 'DARWIN') === 0) {
4747
// macOS: time_sleep_until() may wake up slightly early for unknown reasons. Allow a larger tolerance.
48-
$tolerance = 0.005;
48+
$tolerance = 0.02;
4949
} else {
5050
// Default tolerance
51-
$tolerance = 0.004;
51+
$tolerance = 0.01;
5252
}
5353

54-
if (isWithinTolerance($currentTime, $sleepUntil, $tolerance)) {
54+
if (1 && isWithinTolerance($timeAfterSleep, $targetTime, $tolerance)) {
5555
echo "Success" . PHP_EOL;
5656
} else {
57-
echo "Sleep until (before truncation): {$targetTime}" . PHP_EOL;
58-
echo "Sleep until: {$sleepUntil}" . PHP_EOL;
59-
echo "Now: {$currentTime}" . PHP_EOL;
57+
echo "Failure" . PHP_EOL;
58+
var_dump([
59+
"startTime" => $startTime,
60+
"targetTime" => $targetTime,
61+
"timeAfterSleep" => $timeAfterSleep,
62+
"diff" => $timeAfterSleep - $targetTime,
63+
"tolerance" => $tolerance,
64+
"distanceFromTarget" => abs($timeAfterSleep - $targetTime),
65+
]);
6066
}
6167
?>
6268
--EXPECT--

0 commit comments

Comments
 (0)
0