1--TEST-- 2time_sleep_until() function - basic test for time_sleep_until() 3--SKIPIF-- 4<?php 5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); 6if (!function_exists("time_sleep_until")) die('skip time_sleep_until() not available'); 7?> 8--CREDITS-- 9Manuel Baldassarri mb@ideato.it 10Michele 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 )); 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); 29?> 30--EXPECT-- 31bool(true) 32bool(true) 33