Skip to content

Commit

Permalink
tests: error group callback improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bduranleau-nr committed Aug 28, 2023
1 parent 16ce1ff commit af742dc
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
*/

/*EXPECT_REGEX
Fatal error: Uncaught TypeError: newrelic_set_error_group_callback\(\): Argument #1 \(\$callback\) must be a valid callback, function "This isn't a callback!" not found or invalid function name in .*test_error_group_callback_bad_callback.php:120
Fatal error: Uncaught TypeError: newrelic_set_error_group_callback\(\): Argument #1 \(\$callback\) must be a valid callback, function "This isn't a callback!" not found or invalid function name in .*test_error_group_callback_bad_callback.php:.*
Stack trace:
#0 .*test_error_group_callback_bad_callback.php\(120\): newrelic_set_error_group_callback\('This isn't a ca...'\)
#0 .*test_error_group_callback_bad_callback.php\(.*\): newrelic_set_error_group_callback\('This isn't a ca...'\)
#1 {main}
thrown in .*test_error_group_callback_bad_callback.php on line 120
thrown in .*test_error_group_callback_bad_callback.php on line .*
*/

/*EXPECT_METRICS
Expand All @@ -50,66 +50,6 @@
]
*/

/*EXPECT_ERROR_EVENTS
[
"?? agent run id",
{
"reservoir_size": 100,
"events_seen": 1
},
[
[
{
"type": "TransactionError",
"timestamp": "??",
"error.class": "TypeError",
"error.message": "Uncaught exception 'TypeError' with message 'newrelic_set_error_group_callback(): Argument #1 ($callback) must be a valid callback, function \"This isn't a callback!\" not found or invalid function name' in __FILE__:??",
"transactionName": "OtherTransaction\/php__FILE__",
"duration": "??",
"nr.transactionGuid": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??",
"spanId": "??"
},
{},
{}
]
]
]
*/

/*EXPECT_TRACED_ERRORS
[
"?? agent run id",
[
[
"??",
"OtherTransaction\/php__FILE__",
"Uncaught exception 'TypeError' with message 'newrelic_set_error_group_callback(): Argument #1 ($callback) must be a valid callback, function \"This isn't a callback!\" not found or invalid function name' in __FILE__:??",
"TypeError",
{
"stack_trace": [
" in newrelic_set_error_group_callback called at __FILE__ (??)"
],
"agentAttributes": {},
"intrinsics": {
"totalTime": "??",
"cpu_time": "??",
"cpu_user_time": "??",
"cpu_sys_time": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??"
}
}
]
]
]
*/

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

/*EXPECT_REGEX
Warning: newrelic_set_error_group_callback\(\) expects parameter 1 to be a valid callback, function 'This isn't a callback!' not found or invalid function name in .*test_error_group_callback_bad_callback.php7.php on line 117
Warning: newrelic_set_error_group_callback\(\) expects parameter 1 to be a valid callback, function 'This isn't a callback!' not found or invalid function name in .*test_error_group_callback_bad_callback.php7.php on line .*
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -47,66 +47,6 @@
]
*/

/*EXPECT_ERROR_EVENTS
[
"?? agent run id",
{
"reservoir_size": 100,
"events_seen": 1
},
[
[
{
"type": "TransactionError",
"timestamp": "??",
"error.class": "Exception",
"error.message": "Noticed exception 'Exception' with message 'Sample Exception' in __FILE__:??",
"transactionName": "OtherTransaction\/php__FILE__",
"duration": "??",
"nr.transactionGuid": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??",
"spanId": "??"
},
{},
{}
]
]
]
*/

/*EXPECT_TRACED_ERRORS
[
"?? agent run id",
[
[
"??",
"OtherTransaction\/php__FILE__",
"Noticed exception 'Exception' with message 'Sample Exception' in __FILE__:??",
"Exception",
{
"stack_trace": [
" in alpha called at __FILE__ (??)"
],
"agentAttributes": {},
"intrinsics": {
"totalTime": "??",
"cpu_time": "??",
"cpu_user_time": "??",
"cpu_sys_time": "??",
"guid": "??",
"sampled": true,
"priority": "??",
"traceId": "??"
}
}
]
]
]
*/

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

/*EXPECT
ok - should reject callback with wrong invalid param count
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -99,6 +100,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand All @@ -116,6 +119,8 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback_bad_params);
$result = newrelic_set_error_group_callback($callback_bad_params);

tap_refute($result, "should reject callback with wrong invalid param count");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

/*EXPECT_REGEX
ok - callback registered
request_uri =>
path => test_error_group_callback_bad_return_null.php
method =>
Expand All @@ -20,7 +21,7 @@
klass => Exception
message => Sample Exception
file => .*test_error_group_callback_bad_return_null.php
stack => \[" in alpha called at .*test_error_group_callback_bad_return_null.php \(134\)"\]
stack => \[" in alpha called at .*test_error_group_callback_bad_return_null.php \(.*\)"\]
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -108,6 +109,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand All @@ -129,6 +132,8 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback_bad_return);
$result = newrelic_set_error_group_callback($callback_bad_return);

tap_assert($result, "callback registered");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

/*EXPECT_REGEX
ok - callback registered
request_uri =>
path => test_error_group_callback_bad_return_num.php
method =>
Expand All @@ -20,7 +21,7 @@
klass => Exception
message => Sample Exception
file => .*test_error_group_callback_bad_return_num.php
stack => \[" in alpha called at .*test_error_group_callback_bad_return_num.php \(134\)"\]
stack => \[" in alpha called at .*test_error_group_callback_bad_return_num.php \(.*\)"\]
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -108,6 +109,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand All @@ -129,6 +132,8 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback_bad_return);
$result = newrelic_set_error_group_callback($callback_bad_return);

tap_assert($result, "callback registered");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
klass => Exception
message => Sample Exception
file => .*test_error_group_callback_clobber.php
stack => \[" in alpha called at .*test_error_group_callback_clobber.php \(156\)"\]
stack => \[" in alpha called at .*test_error_group_callback_clobber.php \(.*\)"\]
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -112,6 +112,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
Expand All @@ -133,7 +135,9 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback_alpha);
$result = newrelic_set_error_group_callback($callback_alpha);

tap_assert($result, "callback registered");

$callback_beta = function($txndata, $errdata)
{
Expand All @@ -151,6 +155,8 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback_beta);
$result = newrelic_set_error_group_callback($callback_beta);

tap_assert($result, "second callback registered");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

/*EXPECT
ok - should reject zero args
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -99,11 +100,15 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
newrelic_notice_error(new Exception('Sample Exception'));
}

newrelic_set_error_group_callback();
$result = newrelic_set_error_group_callback();

tap_refute($result, "should reject zero args");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
klass => E_USER_ERROR
message => I'M COVERED IN BEES
file => .*test_error_group_callback_error_non_web.php
stack => \[" in trigger_error called at .*test_error_group_callback_error_non_web.php \(116\)"," in alpha called at .*test_error_group_callback_error_non_web.php \(137\)"\]
stack => \[" in trigger_error called at .*test_error_group_callback_error_non_web.php \(.*\)"," in alpha called at .*test_error_group_callback_error_non_web.php \(.*\)"\]
Fatal error: I'M COVERED IN BEES in .*test_error_group_callback_error_non_web.php on line 116
Fatal error: I'M COVERED IN BEES in .*test_error_group_callback_error_non_web.php on line .*
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -111,6 +111,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

function alpha()
{
trigger_error("I'M COVERED IN BEES", E_USER_ERROR);
Expand All @@ -132,6 +134,7 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback);
$result = newrelic_set_error_group_callback($callback);
tap_assert($result, "callback registered");

alpha();
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

/*EXPECT_REGEX
ok - callback registered
request_uri => \/test_error_group_callback_error_web.php\?foo=1&bar=2
path => .*test_error_group_callback_error_web.php
method => GET
Expand All @@ -22,9 +23,9 @@
klass => E_USER_ERROR
message => I'M COVERED IN BEES
file => .*test_error_group_callback_error_web.php
stack => \[" in trigger_error called at .*test_error_group_callback_error_web.php \(144\)"," in alpha called at .*test_error_group_callback_error_web.php \(165\)"\]
stack => \[" in trigger_error called at .*test_error_group_callback_error_web.php \(.*\)"," in alpha called at .*test_error_group_callback_error_web.php \(.*\)"\]
<br \/>
<b>Fatal error<\/b>: I'M COVERED IN BEES in <b>.*test_error_group_callback_error_web.php<\/b> on line <b>144<\/b><br \/>
<b>Fatal error<\/b>: I'M COVERED IN BEES in <b>.*test_error_group_callback_error_web.php<\/b> on line <b>.*<\/b><br \/>
*/

/*EXPECT_METRICS
Expand Down Expand Up @@ -136,6 +137,8 @@
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');

header('Content-Type: text/html');
header('Content-Type: application/json');

Expand All @@ -160,6 +163,8 @@ function alpha()
return $fingerprint;
};

newrelic_set_error_group_callback($callback);
$result = newrelic_set_error_group_callback($callback);

tap_assert($result, "callback registered");

alpha();
Loading

0 comments on commit af742dc

Please sign in to comment.