]> granicus.if.org Git - php/commitdiff
use busy sleep instead of sleep() for timeout tests
authorAnatol Belski <ab@php.net>
Mon, 16 Mar 2015 20:21:33 +0000 (13:21 -0700)
committerAnatol Belski <ab@php.net>
Mon, 16 Mar 2015 20:21:33 +0000 (13:21 -0700)
12 files changed:
tests/basic/timeout_config.inc [new file with mode: 0644]
tests/basic/timeout_variation_0.phpt
tests/basic/timeout_variation_1.phpt
tests/basic/timeout_variation_10.phpt
tests/basic/timeout_variation_2.phpt
tests/basic/timeout_variation_3.phpt
tests/basic/timeout_variation_4.phpt
tests/basic/timeout_variation_5.phpt
tests/basic/timeout_variation_6.phpt
tests/basic/timeout_variation_7.phpt
tests/basic/timeout_variation_8.phpt
tests/basic/timeout_variation_9.phpt

diff --git a/tests/basic/timeout_config.inc b/tests/basic/timeout_config.inc
new file mode 100644 (file)
index 0000000..e9a6c60
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+$t = 3;
+
+function busy_sleep($how_long)
+{
+       $now = time();
+
+       while($now + $how_long > time());
+}
+
index 31c878dbe61afd9afd536a8a40cc325e4356bd65..51670d5208121bb769fc04ea914a51568869dde3 100644 (file)
@@ -3,12 +3,13 @@ Timeout within while loop
 --FILE--
 <?php
 
-$t = 3;
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 set_time_limit($t);
 
 while(1) { 
        echo 1; 
-       sleep(1);
+       busy_sleep(1);
 }
 
 ?>
index 63c641d757d13562cbda7290ed6bfdc38955842a..3f2d238d02f70d10d46ce301e722912d3db9f47b 100644 (file)
@@ -3,12 +3,14 @@ Timeout within function
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function hello ($t) { 
        echo "call"; 
-       sleep($t*2);
+       busy_sleep($t*2);
 }
 
 hello($t);
index e945bbb0efa4b202879b9d316ddf1480cbeade47..edfb7127a628a60d6a19499f2adf3ace6545f80e 100644 (file)
@@ -3,13 +3,15 @@ Timeout within shutdown function, variation
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function f()
 {
        echo "call";
-       sleep(4);
+       busy_sleep(4);
 }
 
 register_shutdown_function("f");
index b374e9c6847c95b610400d5d029b54c849204f78..74da955d7b88f79439153d672b2333e508a34527 100644 (file)
@@ -3,13 +3,15 @@ Timeout within array_walk
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function cb(&$i, $k, $p)
 { 
        echo 1; 
-       sleep(1);
+       busy_sleep(1);
 }
 
 $a = array(1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1);
index 0de46963d8b62bf9feceb59a21d39a8c6f23b0ff..0c4b9e8e71521fb2e4ee2171ffde59a0dc9ff433 100644 (file)
@@ -3,12 +3,14 @@ Timeout within eval
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function hello ($t) { 
        echo "call", PHP_EOL; 
-       sleep($t*2);
+       busy_sleep($t*2);
 }
 
 eval('hello($t);');
index 053a33af4d662b56418003ddd6473a60c85f445a..102b92afa684578e32121223e26bf3ae006715d4 100644 (file)
@@ -3,12 +3,14 @@ Timeout within call_user_func
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function hello ($t) { 
        echo "call", PHP_EOL; 
-       sleep($t*2);
+       busy_sleep($t*2);
 }
 
 call_user_func('hello', $t);
index e4ccfffa58e125e2843dd19b40c9b4551c768461..38dde0d759a599d2daa93bc732565d4b93549719 100644 (file)
@@ -3,12 +3,14 @@ Timeout within function containing exteption
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function f($t) { 
        echo "call";
-       sleep($t*2);
+       busy_sleep($t*2);
        throw new Exception("never reached here");
 }
 
index 387a358fc84e64a9e72054b417671cfd7888a578..355354fa1a690f7dc2287d68baced185228c46d6 100644 (file)
@@ -3,12 +3,14 @@ Timeout within function trowing exteption before timeout reached
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function f($t) { 
        echo "call";
-       sleep($t-1);
+       busy_sleep($t-1);
        throw new Exception("exception before timeout");
 }
 
index 35852e74953adc48e6b5b359e0119a5b34be0718..5ae8e07a0d1bb4b5446190eda832d475027de4a2 100644 (file)
@@ -3,12 +3,14 @@ Timeout within for loop
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 for($i = 0; $i < 42; $i++) { 
        echo 1; 
-       sleep(1);
+       busy_sleep(1);
 }
 
 ?>
index dfb2d2e69e11b6643e91a56fa24c876cebe56d0c..25a208cca7d5469e10e762ebfc0e0c3ecebaea84 100644 (file)
@@ -3,12 +3,14 @@ Timeout within foreach loop
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 foreach(range(0, 42) as $i) { 
        echo 1; 
-       sleep(1);
+       busy_sleep(1);
 }
 
 ?>
index f51c439eea77ee1172ff96e6a90efe751e5597f9..520b0ee35d74ea7797e6653fd5a8ddf142ef7a9d 100644 (file)
@@ -3,13 +3,15 @@ Timeout within shutdown function
 --FILE--
 <?php
 
+include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
+
 $t = 3;
 set_time_limit($t);
 
 function f()
 {
        echo "call";
-       sleep(4);
+       busy_sleep(4);
 }
 
 register_shutdown_function("f");