Skip to content

Commit e760d94

Browse files
committed
Fix timeout tests
After taking a more detailed look at our commonly failing timeout tests... turns out that most of them are useless as written and don't test what they're supposed to. This PR has a couple of changes: * Tests for timeout in while/for/foreach should just have the loop as an infinite loop. Calling into something like busy_wait means that we just end up always testing whatever busy_wait does. * Tests for timeouts in calls need to be based on something like sleep, otherwise we'd have to introduce a loop, and we'd end up testing timeout of the looping structure instead. Using sleep only works on Windows, because that's the only system where sleep counts towards the timeout. As such, many of those tests are now Windows only. * Removed some tests where I don't see a good way to test what they're supposed to test. E.g. how can we test a timeout in eval() specifically? The shutdown function tests are marked as XFAIL, as we are currently missing a timeout check in call_user_function. I believe that's a legitimate issue. Closes GH-4969.
1 parent 6b7cb4a commit e760d94

12 files changed

+52
-202
lines changed

tests/basic/timeout_config.inc

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/basic/timeout_variation_0.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
Timeout within while loop
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
66
?>
77
--FILE--
88
<?php
99

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
10+
set_time_limit(1);
1111

12-
set_time_limit($t);
13-
14-
while (1) {
15-
busy_wait(1);
12+
$x = true;
13+
$y = 0;
14+
while ($x) {
15+
$y++;
1616
}
1717

1818
?>
1919
never reached here
2020
--EXPECTF--
21-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
21+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_1.phpt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@
22
Timeout within function
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
67
?>
78
--FILE--
89
<?php
910

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
11-
12-
set_time_limit($t);
13-
14-
function hello ($t) {
15-
echo "call";
16-
busy_wait($t*2);
17-
}
18-
19-
hello($t);
11+
set_time_limit(1);
2012

13+
sleep(1);
14+
sleep(1);
2115

2216
?>
2317
never reached here
2418
--EXPECTF--
25-
call
26-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
19+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_10.phpt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
Timeout within shutdown function, variation
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
67
?>
8+
--XFAIL--
9+
Missing timeout check in call_user_function
710
--FILE--
811
<?php
912

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
13+
set_time_limit(1);
1114

12-
set_time_limit($t);
15+
register_shutdown_function("sleep", 1);
16+
register_shutdown_function("sleep", 1);
1317

14-
function f()
15-
{
16-
echo "call";
17-
$startTime = microtime(true);
18-
busy_wait(5);
19-
$diff = microtime(true) - $startTime;
20-
echo "\ntime spent waiting: $diff\n";
21-
}
22-
23-
register_shutdown_function("f");
2418
?>
2519
shutdown happens after here
2620
--EXPECTF--
2721
shutdown happens after here
28-
call
29-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
22+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_2.phpt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
--TEST--
2-
Timeout within array_walk
2+
Timeout within array_map
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
67
?>
78
--FILE--
89
<?php
910

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
11+
set_time_limit(1);
1112

12-
set_time_limit($t);
13+
$a = array(1, 1);
14+
array_map("sleep", $a);
1315

14-
function cb(&$i, $k, $p)
15-
{
16-
busy_wait(1);
17-
}
18-
19-
$startTime = microtime(true);
20-
21-
$a = array(1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1);
22-
array_walk($a, "cb", "junk");
23-
24-
$diff = microtime(true) - $startTime;
25-
echo "time spent waiting: $diff\n";
2616
?>
2717
never reached here
2818
--EXPECTF--
29-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
19+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_3.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/basic/timeout_variation_4.phpt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@
22
Timeout within call_user_func
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
67
?>
78
--FILE--
89
<?php
910

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
11+
set_time_limit(1);
1112

12-
set_time_limit($t);
13-
14-
function hello ($t) {
15-
echo "call", PHP_EOL;
16-
$startTime = microtime(true);
17-
busy_wait($t*2);
18-
$diff = microtime(true) - $startTime;
19-
echo "time spent waiting: $diff\n";
20-
}
21-
22-
call_user_func('hello', $t);
13+
call_user_func('sleep', 1);
14+
call_user_func('sleep', 1);
2315

2416
?>
2517
never reached here
2618
--EXPECTF--
27-
call
28-
29-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
19+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_5.phpt

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/basic/timeout_variation_6.phpt

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/basic/timeout_variation_7.phpt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@
22
Timeout within for loop
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
66
?>
77
--FILE--
88
<?php
99

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
10+
set_time_limit(1);
1111

12-
set_time_limit($t);
13-
14-
$startTime = microtime(true);
15-
16-
for ($i = 0; $i < 42; $i++) {
17-
busy_wait(1);
12+
$y = 0;
13+
for ($i = 0; $i < INF; $i++) {
14+
$y++;
1815
}
1916

20-
$diff = microtime(true) - $startTime;
21-
echo "time spent waiting: $diff\n";
22-
2317
?>
2418
never reached here
2519
--EXPECTF--
26-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
20+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_8.phpt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@
22
Timeout within foreach loop
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
66
?>
77
--FILE--
88
<?php
99

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
10+
set_time_limit(1);
1111

12-
set_time_limit($t);
13-
14-
$startTime = microtime(true);
15-
16-
foreach (range(0, 42) as $i) {
17-
busy_wait(1);
12+
foreach (new InfiniteIterator(new ArrayIterator([1])) as $i) {
1813
}
1914

20-
$diff = microtime(true) - $startTime;
21-
echo "time spent waiting: $diff\n";
22-
2315
?>
2416
never reached here
2517
--EXPECTF--
26-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
18+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

tests/basic/timeout_variation_9.phpt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,20 @@
22
Timeout within shutdown function
33
--SKIPIF--
44
<?php
5-
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
67
?>
8+
--XFAIL--
9+
Missing timeout check in call_user_function
710
--FILE--
811
<?php
912

10-
include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
13+
set_time_limit(1);
14+
register_shutdown_function("sleep", 1);
15+
register_shutdown_function("sleep", 1);
1116

12-
set_time_limit($t);
13-
14-
function f()
15-
{
16-
echo "call";
17-
$startTime = microtime(true);
18-
busy_wait(5);
19-
$diff = microtime(true) - $startTime;
20-
echo "\ntime spent waiting: $diff\n";
21-
}
22-
23-
register_shutdown_function("f");
2417
exit(0);
2518
?>
2619
never reached here
2720
--EXPECTF--
28-
call
29-
Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
21+
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d

0 commit comments

Comments
 (0)