Skip to content

Commit 9599f95

Browse files
committed
Fix phpt asm standalone tests
1 parent f1d36ca commit 9599f95

3 files changed

Lines changed: 28 additions & 22 deletions

File tree

tests/ext/background-sender/agent_sampling-standalone-asm_01.phpt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,36 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplingc
1717
include __DIR__ . '/../includes/request_replayer.inc';
1818

1919
$rr = new RequestReplayer();
20-
$rr->maxIteration = 2000;
2120

2221
$picked = 0;
2322
$notPicked = 0;
24-
$maxIterations = 10;
23+
$maxIterations = 5;
2524
for ($i = 0; $i < $maxIterations; $i++)
2625
{
2726
//Do call and get sampling
2827
\DDTrace\start_span();
2928
\DDTrace\close_span();
30-
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
29+
// Flush the span synchronously before reading from the request replayer
30+
dd_trace_internal_fn("synchronous_flush");
31+
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
3132
$spans = $root["chunks"][0]["spans"] ?? $root[0];
3233
$sampling = $spans[0]["metrics"]["_sampling_priority_v1"];
33-
dd_trace_internal_fn("synchronous_flush");
3434

35-
if($sampling == 1 && $picked == 1) //Start again, probably different minute
36-
{
37-
$notPicked = 0;
38-
continue;
39-
} else if ($sampling == 1) { //First picked
35+
if ($sampling == 1) { // First pick this minute (or minute rollover)
4036
$picked = 1;
41-
} else if ($sampling == 0) {
42-
$notPicked++;
43-
} else if($picked == 0 && $sampling == 0) {
44-
//If this happen means something is odd already
45-
break;
37+
$notPicked = 0;
38+
continue;
4639
}
40+
41+
// Ignore zeros until we've seen the first 1
42+
if ($picked == 0) {
43+
continue;
44+
}
45+
46+
// After first 1, count zeros
47+
if ($sampling == 0) {
48+
$notPicked++;
49+
}
4750
if ($picked == 1 && $notPicked == 2) {
4851
break;
4952
}

tests/ext/background-sender/agent_sampling-standalone-asm_02.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplingb
1717
include __DIR__ . '/../includes/request_replayer.inc';
1818

1919
$rr = new RequestReplayer();
20-
$rr->maxIteration = 2000;
2120

2221
$get_sampling = function() use ($rr) {
2322
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
@@ -27,21 +26,23 @@ $get_sampling = function() use ($rr) {
2726

2827
\DDTrace\start_span();
2928
\DDTrace\close_span();
29+
dd_trace_internal_fn("synchronous_flush");
3030
echo "First call it is used as heartbeat: {$get_sampling()}\n";
3131

32-
dd_trace_internal_fn("synchronous_flush");
3332

3433
\DDTrace\start_span();
3534
DDTrace\Testing\emit_asm_event();
3635
\DDTrace\close_span();
37-
echo "This call has the same sample rate: {$get_sampling()}\n";
38-
3936
// reset it for other tests
4037
dd_trace_internal_fn("synchronous_flush");
38+
echo "This call has the same sample rate: {$get_sampling()}\n";
39+
40+
4141

4242
\DDTrace\start_span();
4343
DDTrace\Testing\emit_asm_event();
4444
\DDTrace\close_span();
45+
dd_trace_internal_fn("synchronous_flush");
4546
echo "This call also has the same sample rate: {$get_sampling()}\n";
4647

4748
?>

tests/ext/background-sender/agent_sampling-standalone-asm_03.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ datadog.trace.agent_test_session_token=background-sender/agent_samplinga
2222
include __DIR__ . '/../includes/request_replayer.inc';
2323

2424
$rr = new RequestReplayer();
25-
$rr->maxIteration = 2000;
2625

2726
$get_sampling = function() use ($rr) {
2827
$root = json_decode($rr->waitForDataAndReplay()["body"], true);
@@ -32,19 +31,22 @@ $get_sampling = function() use ($rr) {
3231

3332
\DDTrace\start_span();
3433
\DDTrace\close_span();
34+
dd_trace_internal_fn("synchronous_flush");
35+
3536
echo "First call it is used as heartbeat: {$get_sampling()}\n";
3637

37-
dd_trace_internal_fn("synchronous_flush");
3838

3939
\DDTrace\start_span();
4040
\DDTrace\close_span();
41-
echo "This call has the same sample rate: {$get_sampling()}\n";
42-
4341
// reset it for other tests
4442
dd_trace_internal_fn("synchronous_flush");
43+
echo "This call has the same sample rate: {$get_sampling()}\n";
44+
45+
4546

4647
\DDTrace\start_span();
4748
\DDTrace\close_span();
49+
dd_trace_internal_fn("synchronous_flush");
4850
echo "This call also has the same sample rate: {$get_sampling()}\n";
4951
?>
5052
--EXPECTF--

0 commit comments

Comments
 (0)