Return to time_sleep_until_basic.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / misc |
1.1 misho 1: --TEST-- 2: time_sleep_until() function - basic test for time_sleep_until() 3: --SKIPIF-- 4: <?php 5: if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 6: if (!function_exists("time_sleep_until")) die('skip time_sleep_until() not available'); 7: ?> 8: --CREDITS-- 9: Manuel Baldassarri mb@ideato.it 10: Michele Orselli mo@ideato.it 11: #PHPTestFest Cesena Italia on 2009-06-20 12: --FILE-- 13: <?php 14: $time = microtime(true) + 2; 15: var_dump(time_sleep_until( (int)$time )); 1.1.1.2 ! misho 16: $now = microtime(true); ! 17: if(substr(PHP_OS, 0, 3) == 'WIN' ) { ! 18: // on windows, time_sleep_until has millisecond accuracy while microtime() is accurate ! 19: // to 10th of a second. this means there can be up to a .9 millisecond difference ! 20: // which will fail this test. this test randomly fails on Windows and this is the cause. ! 21: // ! 22: // fix: round to nearest millisecond ! 23: // passes for up to .5 milliseconds less, fails for more than .5 milliseconds ! 24: // should be fine since time_sleep_until() on Windows is accurate to the ! 25: // millisecond(.5 rounded up is 1 millisecond) ! 26: $now = round($now, 3); ! 27: } ! 28: var_dump($now >= (int)$time); 1.1 misho 29: ?> 30: --EXPECT-- 31: bool(true) 32: bool(true)