Skip to content

Commit

Permalink
test fixes + added skipif for slow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weltling committed Mar 16, 2015
1 parent 042dd86 commit fd51bd4
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 26 deletions.
6 changes: 3 additions & 3 deletions tests/basic/timeout_config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

$t = 3;

function busy_sleep($how_long)
function busy_wait($how_long)
{
$now = time();
$until = time() + $how_long;

while($now + $how_long > time());
while ($until > time());
}

11 changes: 7 additions & 4 deletions tests/basic/timeout_variation_0.phpt
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
--TEST--
Timeout within while loop
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";

$t = 3;
set_time_limit($t);

while(1) {
echo 1;
busy_sleep(1);
while (1) {
busy_wait(1);
}

?>
never reached here
--EXPECTF--
111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_1.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within function
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,7 +14,7 @@ set_time_limit($t);

function hello ($t) {
echo "call";
busy_sleep($t*2);
busy_wait($t*2);
}

hello($t);
Expand Down
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_10.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within shutdown function, variation
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -11,7 +15,7 @@ set_time_limit($t);
function f()
{
echo "call";
busy_sleep(4);
busy_wait(4);
}

register_shutdown_function("f");
Expand Down
8 changes: 5 additions & 3 deletions tests/basic/timeout_variation_2.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within array_walk
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,8 +14,7 @@ set_time_limit($t);

function cb(&$i, $k, $p)
{
echo 1;
busy_sleep(1);
busy_wait(1);
}

$a = array(1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1);
Expand All @@ -20,5 +23,4 @@ array_walk($a, "cb", "junk");
?>
never reached here
--EXPECTF--
111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_3.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within eval
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,7 +14,7 @@ set_time_limit($t);

function hello ($t) {
echo "call", PHP_EOL;
busy_sleep($t*2);
busy_wait($t*2);
}

eval('hello($t);');
Expand Down
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_4.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within call_user_func
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,7 +14,7 @@ set_time_limit($t);

function hello ($t) {
echo "call", PHP_EOL;
busy_sleep($t*2);
busy_wait($t*2);
}

call_user_func('hello', $t);
Expand Down
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_5.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within function containing exteption
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,7 +14,7 @@ set_time_limit($t);

function f($t) {
echo "call";
busy_sleep($t*2);
busy_wait($t*2);
throw new Exception("never reached here");
}

Expand Down
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_6.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within function trowing exteption before timeout reached
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -10,7 +14,7 @@ set_time_limit($t);

function f($t) {
echo "call";
busy_sleep($t-1);
busy_wait($t-1);
throw new Exception("exception before timeout");
}

Expand Down
10 changes: 6 additions & 4 deletions tests/basic/timeout_variation_7.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within for loop
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -8,13 +12,11 @@ include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";
$t = 3;
set_time_limit($t);

for($i = 0; $i < 42; $i++) {
echo 1;
busy_sleep(1);
for ($i = 0; $i < 42; $i++) {
busy_wait(1);
}

?>
never reached here
--EXPECTF--
111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
12 changes: 7 additions & 5 deletions tests/basic/timeout_variation_8.phpt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
--TEST--
Timeout within foreach loop
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

$t = 3;
include dirname(__FILE__) . DIRECTORY_SEPARATOR . "timeout_config.inc";

$t = 3;
set_time_limit($t);

foreach(range(0, 42) as $i) {
echo 1;
busy_sleep(1);
foreach (range(0, 42) as $i) {
busy_wait(1);
}

?>
never reached here
--EXPECTF--
111
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
6 changes: 5 additions & 1 deletion tests/basic/timeout_variation_9.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Timeout within shutdown function
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

Expand All @@ -11,7 +15,7 @@ set_time_limit($t);
function f()
{
echo "call";
busy_sleep(4);
busy_wait(4);
}

register_shutdown_function("f");
Expand Down

0 comments on commit fd51bd4

Please sign in to comment.