summaryrefslogtreecommitdiff
path: root/tests/basic
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-12-05 09:13:57 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-12-05 11:19:23 +0100
commite760d94f4bb4d0802e89af0927cecfb479cba024 (patch)
tree82b272b399fbbb183a3246e1a97636370e58374a /tests/basic
parent6b7cb4a8d70cd3a4f153e5097f9c9caea3ed0b4d (diff)
downloadphp-git-e760d94f4bb4d0802e89af0927cecfb479cba024.tar.gz
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.
Diffstat (limited to 'tests/basic')
-rw-r--r--tests/basic/timeout_config.inc10
-rw-r--r--tests/basic/timeout_variation_0.phpt14
-rw-r--r--tests/basic/timeout_variation_1.phpt19
-rw-r--r--tests/basic/timeout_variation_10.phpt23
-rw-r--r--tests/basic/timeout_variation_2.phpt24
-rw-r--r--tests/basic/timeout_variation_3.phpt28
-rw-r--r--tests/basic/timeout_variation_4.phpt22
-rw-r--r--tests/basic/timeout_variation_5.phpt27
-rw-r--r--tests/basic/timeout_variation_6.phpt29
-rw-r--r--tests/basic/timeout_variation_7.phpt18
-rw-r--r--tests/basic/timeout_variation_8.phpt16
-rw-r--r--tests/basic/timeout_variation_9.phpt24
12 files changed, 52 insertions, 202 deletions
diff --git a/tests/basic/timeout_config.inc b/tests/basic/timeout_config.inc
deleted file mode 100644
index 5cd156f471..0000000000
--- a/tests/basic/timeout_config.inc
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-$t = 3;
-
-function busy_wait($how_long) {
- $until = microtime(true) + $how_long;
- do {
- for ($i = 0; $i < 1000000; $i++);
- } while ($until > microtime(true));
-}
diff --git a/tests/basic/timeout_variation_0.phpt b/tests/basic/timeout_variation_0.phpt
index be868392b4..ac514e1f9a 100644
--- a/tests/basic/timeout_variation_0.phpt
+++ b/tests/basic/timeout_variation_0.phpt
@@ -2,20 +2,20 @@
Timeout within while loop
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
-
-while (1) {
- busy_wait(1);
+$x = true;
+$y = 0;
+while ($x) {
+ $y++;
}
?>
never reached here
--EXPECTF--
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_1.phpt b/tests/basic/timeout_variation_1.phpt
index 238041955e..c935d390fa 100644
--- a/tests/basic/timeout_variation_1.phpt
+++ b/tests/basic/timeout_variation_1.phpt
@@ -2,25 +2,18 @@
Timeout within function
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
-
-set_time_limit($t);
-
-function hello ($t) {
- echo "call";
- busy_wait($t*2);
-}
-
-hello($t);
+set_time_limit(1);
+sleep(1);
+sleep(1);
?>
never reached here
--EXPECTF--
-call
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_10.phpt b/tests/basic/timeout_variation_10.phpt
index 44e1b93135..b067238db5 100644
--- a/tests/basic/timeout_variation_10.phpt
+++ b/tests/basic/timeout_variation_10.phpt
@@ -2,28 +2,21 @@
Timeout within shutdown function, variation
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
+--XFAIL--
+Missing timeout check in call_user_function
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
+register_shutdown_function("sleep", 1);
+register_shutdown_function("sleep", 1);
-function f()
-{
- echo "call";
- $startTime = microtime(true);
- busy_wait(5);
- $diff = microtime(true) - $startTime;
- echo "\ntime spent waiting: $diff\n";
-}
-
-register_shutdown_function("f");
?>
shutdown happens after here
--EXPECTF--
shutdown happens after here
-call
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_2.phpt b/tests/basic/timeout_variation_2.phpt
index 4acf5cd219..81b1b1b479 100644
--- a/tests/basic/timeout_variation_2.phpt
+++ b/tests/basic/timeout_variation_2.phpt
@@ -1,29 +1,19 @@
--TEST--
-Timeout within array_walk
+Timeout within array_map
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
+$a = array(1, 1);
+array_map("sleep", $a);
-function cb(&$i, $k, $p)
-{
- busy_wait(1);
-}
-
-$startTime = microtime(true);
-
-$a = array(1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1);
-array_walk($a, "cb", "junk");
-
-$diff = microtime(true) - $startTime;
-echo "time spent waiting: $diff\n";
?>
never reached here
--EXPECTF--
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_3.phpt b/tests/basic/timeout_variation_3.phpt
deleted file mode 100644
index 317d1b44ab..0000000000
--- a/tests/basic/timeout_variation_3.phpt
+++ /dev/null
@@ -1,28 +0,0 @@
---TEST--
-Timeout within eval
---SKIPIF--
-<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
-?>
---FILE--
-<?php
-
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
-
-set_time_limit($t);
-
-function hello ($t) {
- echo "call", PHP_EOL;
- $startTime = microtime(true);
- busy_wait($t*2);
- $diff = microtime(true) - $startTime;
- echo "time spent waiting: $diff\n";
-}
-
-eval('hello($t);');
-?>
-never reached here
---EXPECTF--
-call
-
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_4.phpt b/tests/basic/timeout_variation_4.phpt
index 98f4d6ca8e..380a740a71 100644
--- a/tests/basic/timeout_variation_4.phpt
+++ b/tests/basic/timeout_variation_4.phpt
@@ -2,28 +2,18 @@
Timeout within call_user_func
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
-
-function hello ($t) {
- echo "call", PHP_EOL;
- $startTime = microtime(true);
- busy_wait($t*2);
- $diff = microtime(true) - $startTime;
- echo "time spent waiting: $diff\n";
-}
-
-call_user_func('hello', $t);
+call_user_func('sleep', 1);
+call_user_func('sleep', 1);
?>
never reached here
--EXPECTF--
-call
-
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_5.phpt b/tests/basic/timeout_variation_5.phpt
deleted file mode 100644
index 6915623c6b..0000000000
--- a/tests/basic/timeout_variation_5.phpt
+++ /dev/null
@@ -1,27 +0,0 @@
---TEST--
-Timeout within function containing exception
---SKIPIF--
-<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
-?>
---FILE--
-<?php
-
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
-
-set_time_limit($t);
-
-function f($t) {
- echo "call";
- $startTime = microtime(true);
- busy_wait($t*2);
- $diff = microtime(true) - $startTime;
- throw new Exception("never reached here (time spent waiting: $diff)");
-}
-
-f($t);
-?>
-never reached here
---EXPECTF--
-call
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_6.phpt b/tests/basic/timeout_variation_6.phpt
deleted file mode 100644
index 7b0a93d38e..0000000000
--- a/tests/basic/timeout_variation_6.phpt
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-Timeout within function trowing exception before timeout reached
---SKIPIF--
-<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
-?>
---FILE--
-<?php
-
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
-
-set_time_limit($t);
-
-function f($t) {
- echo "call";
- busy_wait($t-1);
- throw new Exception("exception before timeout");
-}
-
-f($t);
-?>
-never reached here
---EXPECTF--
-call
-Fatal error: Uncaught Exception: exception before timeout in %s:%d
-Stack trace:
-#0 %s(%d): f(%d)
-#1 {main}
- thrown in %s on line %d
diff --git a/tests/basic/timeout_variation_7.phpt b/tests/basic/timeout_variation_7.phpt
index 849ac55e0d..0401240ba9 100644
--- a/tests/basic/timeout_variation_7.phpt
+++ b/tests/basic/timeout_variation_7.phpt
@@ -2,25 +2,19 @@
Timeout within for loop
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
-
-$startTime = microtime(true);
-
-for ($i = 0; $i < 42; $i++) {
- busy_wait(1);
+$y = 0;
+for ($i = 0; $i < INF; $i++) {
+ $y++;
}
-$diff = microtime(true) - $startTime;
-echo "time spent waiting: $diff\n";
-
?>
never reached here
--EXPECTF--
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_8.phpt b/tests/basic/timeout_variation_8.phpt
index 51022250f0..16e2567e66 100644
--- a/tests/basic/timeout_variation_8.phpt
+++ b/tests/basic/timeout_variation_8.phpt
@@ -2,25 +2,17 @@
Timeout within foreach loop
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
-set_time_limit($t);
-
-$startTime = microtime(true);
-
-foreach (range(0, 42) as $i) {
- busy_wait(1);
+foreach (new InfiniteIterator(new ArrayIterator([1])) as $i) {
}
-$diff = microtime(true) - $startTime;
-echo "time spent waiting: $diff\n";
-
?>
never reached here
--EXPECTF--
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
diff --git a/tests/basic/timeout_variation_9.phpt b/tests/basic/timeout_variation_9.phpt
index ffe4553e49..e59ae242dc 100644
--- a/tests/basic/timeout_variation_9.phpt
+++ b/tests/basic/timeout_variation_9.phpt
@@ -2,28 +2,20 @@
Timeout within shutdown function
--SKIPIF--
<?php
- if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+if (PHP_OS_FAMILY !== "Windows") die("skip Windows only test");
?>
+--XFAIL--
+Missing timeout check in call_user_function
--FILE--
<?php
-include __DIR__ . DIRECTORY_SEPARATOR . "timeout_config.inc";
+set_time_limit(1);
+register_shutdown_function("sleep", 1);
+register_shutdown_function("sleep", 1);
-set_time_limit($t);
-
-function f()
-{
- echo "call";
- $startTime = microtime(true);
- busy_wait(5);
- $diff = microtime(true) - $startTime;
- echo "\ntime spent waiting: $diff\n";
-}
-
-register_shutdown_function("f");
exit(0);
?>
never reached here
--EXPECTF--
-call
-Fatal error: Maximum execution time of 3 seconds exceeded in %s on line %d
+Fatal error: Maximum execution time of 1 second exceeded in %s on line %d