|
11 | 11 | #PHPTestFest Cesena Italia on 2009-06-20
|
12 | 12 | --FILE--
|
13 | 13 | <?php
|
14 |
| - $time = microtime(true) + 2; |
15 |
| - var_dump(time_sleep_until( (int)$time )); |
16 |
| - $now = microtime(true); |
17 |
| - if(substr(PHP_OS, 0, 3) == 'WIN' ) { |
| 14 | +$time = microtime(true) + 2; |
| 15 | +$sleepUntil = (int) $time; |
| 16 | +var_dump(time_sleep_until($sleepUntil)); |
| 17 | +$now = microtime(true); |
| 18 | +if (substr(PHP_OS, 0, 3) == 'WIN') { |
18 | 19 | // on windows, time_sleep_until has millisecond accuracy while microtime() is accurate
|
19 | 20 | // to 10th of a second. this means there can be up to a .9 millisecond difference
|
20 | 21 | // which will fail this test. this test randomly fails on Windows and this is the cause.
|
|
26 | 27 | // In practice, on slower machines even that can fail, so giving yet 50ms or more.
|
27 | 28 | $tmp = round($now, 3);
|
28 | 29 | $now = $tmp >= (int)$time ? $tmp : $tmp + .05;
|
29 |
| - } |
30 |
| - var_dump($now >= (int)$time); |
| 30 | +} |
| 31 | + |
| 32 | +if ($now >= $sleepUntil) { |
| 33 | + echo "Success\n"; |
| 34 | +} else { |
| 35 | + echo "Sleep until (before truncation): ", $time, "\n"; |
| 36 | + echo "Sleep until: ", $sleepUntil, "\n"; |
| 37 | + echo "Now: ", $now, "\n"; |
| 38 | +} |
| 39 | + |
31 | 40 | ?>
|
32 | 41 | --EXPECT--
|
33 | 42 | bool(true)
|
34 |
| -bool(true) |
| 43 | +Success |
0 commit comments