Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit c4acca0

Browse files
committed
Fix timout tests on travis when memcheks run
1 parent c7c8e91 commit c4acca0

6 files changed

+63
-21
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ before_install:
2626
- sudo apt-get install -y libv8-${V8}-dev
2727

2828
before_script:
29+
- echo 'variables_order = "EGPCS"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
2930
- phpize && ./configure && make
3031

3132
script:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PHP extension for V8 JavaScript engine
88

99

1010
## Developers note
11-
11+
- to be able to customize some tests make sure you have `` in your php.ini
1212
- `export DEV_TESTS=1` allows to run tests that made for development reason (e.g. test some weird behavior or for debugging)
1313
- To prevent asking test suite to send results to PHP QA team do `export NO_INTERACTION=1`
1414

tests/V8Isolate_limit_time.phpt

+19-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@ $file_name = 'test.js';
2525

2626
$script = new v8\Script($context, new \v8\StringValue($isolate, $source), new \v8\ScriptOrigin($file_name));
2727

28-
$time_limit = 1.5;
28+
// NOTE: this check is a bit fragile but should fits our need
29+
$needs_more_time = isset($_ENV['TRAVIS']) && isset($_ENV['TEST_PHP_ARGS']) && $_ENV['TEST_PHP_ARGS'] == '-m';
30+
31+
if ($needs_more_time) {
32+
// On travis when valgrind active it takes more time to complete all operations so we just increase initial limits
33+
$time_limit = 5.0;
34+
$low_range = 4.5;
35+
$high_range = 7.5;
36+
} else {
37+
$time_limit = 1.5;
38+
$low_range = 1.45;
39+
$high_range = 1.6;
40+
}
41+
2942
$helper->assert('Time limit accessor report no hit', false === $isolate->IsTimeLimitHit());
3043
$helper->assert('Get time limit default value is zero', 0.0 === $isolate->GetTimeLimit());
3144
$isolate->SetTimeLimit($time_limit);
@@ -44,7 +57,7 @@ try {
4457
$helper->line();
4558
$t = microtime(true) - $t;
4659
$helper->dump(round($t, 9));
47-
$helper->assert('Script execution time is between 1.500 and 1.600', $t >= 1.500 && $t < 1.599);
60+
$helper->assert("Script execution time is within specified range ({$low_range}, {$high_range})", $t >= $low_range && $t < $high_range);
4861
}
4962

5063
$helper->assert('Get time limit returns valid value', $time_limit === $isolate->GetTimeLimit());
@@ -61,7 +74,7 @@ object(v8\Isolate)#3 (5) {
6174
["snapshot":"v8\Isolate":private]=>
6275
NULL
6376
["time_limit":"v8\Isolate":private]=>
64-
float(1.5)
77+
float(%f)
6578
["time_limit_hit":"v8\Isolate":private]=>
6679
bool(false)
6780
["memory_limit":"v8\Isolate":private]=>
@@ -73,16 +86,16 @@ object(v8\Isolate)#3 (5) {
7386
v8\Exceptions\TimeLimitException: Time limit exceeded
7487
script execution terminated
7588

76-
float(1.5%d)
77-
Script execution time is between 1.500 and 1.600: ok
89+
float(%f)
90+
Script execution time is within specified range (%f, %f): ok
7891
Get time limit returns valid value: ok
7992
Time limit accessor report hit: ok
8093

8194
object(v8\Isolate)#3 (5) {
8295
["snapshot":"v8\Isolate":private]=>
8396
NULL
8497
["time_limit":"v8\Isolate":private]=>
85-
float(1.5)
98+
float(%f)
8699
["time_limit_hit":"v8\Isolate":private]=>
87100
bool(true)
88101
["memory_limit":"v8\Isolate":private]=>

tests/V8Isolate_limit_time_nested.phpt

+20-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@ $file_name1 = 'test.js';
5757

5858
$script1 = new v8\Script($context1, new \v8\StringValue($isolate1, $source1), new \v8\ScriptOrigin($file_name1));
5959

60-
$isolate1->SetTimeLimit(1.5);
60+
// NOTE: this check is a bit fragile but should fits our need
61+
$needs_more_time = isset($_ENV['TRAVIS']) && isset($_ENV['TEST_PHP_ARGS']) && $_ENV['TEST_PHP_ARGS'] == '-m';
62+
63+
if ($needs_more_time) {
64+
// On travis when valgrind active it takes more time to complete all operations so we just increase initial limits
65+
$time_limit = 5.0;
66+
$low_range = 4.5;
67+
$high_range = 7.5;
68+
} else {
69+
$time_limit = 1.5;
70+
$low_range = 1.45;
71+
$high_range = 1.6;
72+
}
73+
74+
$isolate1->SetTimeLimit($time_limit);
6175
$helper->dump($isolate1);
6276
$helper->line();
6377

@@ -71,7 +85,7 @@ try {
7185
$helper->line();
7286
$t = microtime(true) - $t;
7387
$helper->dump(round($t, 9));
74-
$helper->assert('Script execution time is between 1.500 and 1.600', $t >= 1.500 && $t < 1.599);
88+
$helper->assert("Script execution time is within specified range ({$low_range}, {$high_range})", $t >= $low_range && $t < $high_range);
7589
}
7690

7791
$helper->line();
@@ -82,7 +96,7 @@ object(v8\Isolate)#2 (5) {
8296
["snapshot":"v8\Isolate":private]=>
8397
NULL
8498
["time_limit":"v8\Isolate":private]=>
85-
float(1.5)
99+
float(%f)
86100
["time_limit_hit":"v8\Isolate":private]=>
87101
bool(false)
88102
["memory_limit":"v8\Isolate":private]=>
@@ -100,14 +114,14 @@ function call terminated
100114
v8\Exceptions\TimeLimitException: Time limit exceeded
101115
script execution terminated
102116

103-
float(1.5%d)
104-
Script execution time is between 1.500 and 1.600: ok
117+
float(%f)
118+
Script execution time is within specified range (%f, %f): ok
105119

106120
object(v8\Isolate)#2 (5) {
107121
["snapshot":"v8\Isolate":private]=>
108122
NULL
109123
["time_limit":"v8\Isolate":private]=>
110-
float(1.5)
124+
float(%f)
111125
["time_limit_hit":"v8\Isolate":private]=>
112126
bool(true)
113127
["memory_limit":"v8\Isolate":private]=>

tests/V8Isolate_limit_time_not_hit.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object(v8\Isolate)#3 (5) {
6060
["snapshot":"v8\Isolate":private]=>
6161
NULL
6262
["time_limit":"v8\Isolate":private]=>
63-
float(1.5)
63+
float(%f)
6464
["time_limit_hit":"v8\Isolate":private]=>
6565
bool(false)
6666
["memory_limit":"v8\Isolate":private]=>
@@ -81,7 +81,7 @@ object(v8\Isolate)#3 (5) {
8181
["snapshot":"v8\Isolate":private]=>
8282
NULL
8383
["time_limit":"v8\Isolate":private]=>
84-
float(1.5)
84+
float(%f)
8585
["time_limit_hit":"v8\Isolate":private]=>
8686
bool(false)
8787
["memory_limit":"v8\Isolate":private]=>

tests/V8Isolate_limit_time_set_during_execution.phpt

+20-6
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ $global_template1 = new v8\ObjectTemplate($isolate1);
1717

1818
$context1 = new v8\Context($isolate1, $extensions1, $global_template1);
1919

20-
$func = new v8\FunctionObject($context1, function (\v8\FunctionCallbackInfo $info) use (&$helper) {
20+
// NOTE: this check is a bit fragile but should fits our need
21+
$needs_more_time = isset($_ENV['TRAVIS']) && isset($_ENV['TEST_PHP_ARGS']) && $_ENV['TEST_PHP_ARGS'] == '-m';
22+
23+
if ($needs_more_time) {
24+
// On travis when valgrind active it takes more time to complete all operations so we just increase initial limits
25+
$time_limit = 5.0;
26+
$low_range = 4.5;
27+
$high_range = 7.5;
28+
} else {
29+
$time_limit = 1.5;
30+
$low_range = 1.45;
31+
$high_range = 1.6;
32+
}
33+
34+
$func = new v8\FunctionObject($context1, function (\v8\FunctionCallbackInfo $info) use (&$helper, $time_limit) {
2135
$isolate = $info->GetIsolate();
22-
$isolate->SetTimeLimit(1.5);
36+
$isolate->SetTimeLimit($time_limit);
2337
});
2438

2539

@@ -46,7 +60,7 @@ try {
4660
$helper->line();
4761
$t = microtime(true) - $t;
4862
$helper->dump(round($t, 9));
49-
$helper->assert('Script execution time is between 1.500 and 1.600', $t >= 1.500 && $t < 1.599);
63+
$helper->assert("Script execution time is within specified range ({$low_range}, {$high_range})", $t >= $low_range && $t < $high_range);
5064
}
5165

5266
$helper->line();
@@ -70,14 +84,14 @@ object(v8\Isolate)#2 (5) {
7084
v8\Exceptions\TimeLimitException: Time limit exceeded
7185
script execution terminated
7286

73-
float(1.5%d)
74-
Script execution time is between 1.500 and 1.600: ok
87+
float(%f)
88+
Script execution time is within specified range (%f, %f): ok
7589

7690
object(v8\Isolate)#2 (5) {
7791
["snapshot":"v8\Isolate":private]=>
7892
NULL
7993
["time_limit":"v8\Isolate":private]=>
80-
float(1.5)
94+
float(%f)
8195
["time_limit_hit":"v8\Isolate":private]=>
8296
bool(true)
8397
["memory_limit":"v8\Isolate":private]=>

0 commit comments

Comments
 (0)