Skip to content

Commit f2c18ed

Browse files
authored
tests: make tests deterministic (#1087)
Force non-zero duration of helper user function. When tests execute fast enough, the helper function's segment start time and end time are equal and this causes the segment to be dropped. To address this test instability, non-zero duration is forced on test helper user functions. This is a follow up to #781.
1 parent afc6d35 commit f2c18ed

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

tests/integration/jit/function/test_span_class_function.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
newrelic_add_custom_tracer('Classname::functionName');
245245
function main()
246246
{
247+
time_nanosleep(0, 50000); // force non-zero duration for the segment not to be dropped.
247248
echo 'Hello';
248249
}
249250
main();

tests/integration/jit/tracing/test_span_class_function.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
newrelic_add_custom_tracer('Classname::functionName');
244244
function main()
245245
{
246+
time_nanosleep(0, 50000); // force non-zero duration for the segment not to be dropped.
246247
echo 'Hello';
247248
}
248249
main();

tests/integration/lang/trampoline/test_trampoline_02.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@
7777
$anon = new class() {
7878
function execute()
7979
{
80+
time_nanosleep(0, 50000); // force non-zero duration for the segment not to be dropped.
8081
new ReflectionClass('Wrapper');
8182
}
8283
};
8384

8485
$anon2 = new class() {
8586
function execute()
8687
{
88+
time_nanosleep(0, 50000); // force non-zero duration for the segment not to be dropped.
8789
new ReflectionClass('Wrapper');
8890
}
8991
};

tests/integration/opcache/disabled/test_span_class_function.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
newrelic_add_custom_tracer('Classname::functionName');
246246
function main()
247247
{
248+
time_nanosleep(0, 50000); // force non-zero duration for the segment not to be dropped.
248249
echo 'Hello';
249250
}
250251
main();

0 commit comments

Comments
 (0)