From af742dccca975e2841f3d47d61e30d2361f53134 Mon Sep 17 00:00:00 2001 From: Brian Duranleau Date: Mon, 28 Aug 2023 14:50:07 -0500 Subject: [PATCH] tests: error group callback improvements --- ...test_error_group_callback_bad_callback.php | 66 +------------------ ...error_group_callback_bad_callback.php7.php | 62 +---------------- .../test_error_group_callback_bad_params.php | 7 +- ...t_error_group_callback_bad_return_null.php | 9 ++- ...st_error_group_callback_bad_return_num.php | 9 ++- .../test_error_group_callback_clobber.php | 12 +++- ...st_error_group_callback_empty_callback.php | 7 +- ...est_error_group_callback_error_non_web.php | 9 ++- .../test_error_group_callback_error_web.php | 11 +++- ...error_group_callback_exception_non_web.php | 9 ++- ...est_error_group_callback_exception_web.php | 9 ++- ...st_error_group_callback_max_string_len.php | 9 ++- 12 files changed, 74 insertions(+), 145 deletions(-) diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php b/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php index 91c48eb9d..89d4f9755 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php @@ -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 @@ -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')); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php7.php b/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php7.php index a9f4ef9c8..e17dd5bcc 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php7.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_bad_callback.php7.php @@ -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 @@ -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')); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_bad_params.php b/tests/integration/api/error_group_callback/test_error_group_callback_bad_params.php index 9f2147cbf..7e56d8843 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_bad_params.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_bad_params.php @@ -12,6 +12,7 @@ */ /*EXPECT +ok - should reject callback with wrong invalid param count */ /*EXPECT_METRICS @@ -99,6 +100,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_null.php b/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_null.php index 8603dd346..9c735aa18 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_null.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_null.php @@ -12,6 +12,7 @@ */ /*EXPECT_REGEX +ok - callback registered request_uri => path => test_error_group_callback_bad_return_null.php method => @@ -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 @@ -108,6 +109,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_num.php b/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_num.php index 287046e3d..305547e9a 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_num.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_bad_return_num.php @@ -12,6 +12,7 @@ */ /*EXPECT_REGEX +ok - callback registered request_uri => path => test_error_group_callback_bad_return_num.php method => @@ -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 @@ -108,6 +109,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_clobber.php b/tests/integration/api/error_group_callback/test_error_group_callback_clobber.php index b46c42bdb..4c7762964 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_clobber.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_clobber.php @@ -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 @@ -112,6 +112,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -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) { @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_empty_callback.php b/tests/integration/api/error_group_callback/test_error_group_callback_empty_callback.php index 092c1f9a4..2993b6007 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_empty_callback.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_empty_callback.php @@ -12,6 +12,7 @@ */ /*EXPECT +ok - should reject zero args */ /*EXPECT_METRICS @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_error_non_web.php b/tests/integration/api/error_group_callback/test_error_group_callback_error_non_web.php index 3fa29d4f5..92d302377 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_error_non_web.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_error_non_web.php @@ -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 @@ -111,6 +111,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { trigger_error("I'M COVERED IN BEES", E_USER_ERROR); @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_error_web.php b/tests/integration/api/error_group_callback/test_error_group_callback_error_web.php index 241337b27..678b89d4e 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_error_web.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_error_web.php @@ -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 @@ -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 \(.*\)"\]
-Fatal error<\/b>: I'M COVERED IN BEES in .*test_error_group_callback_error_web.php<\/b> on line 144<\/b>
+Fatal error<\/b>: I'M COVERED IN BEES in .*test_error_group_callback_error_web.php<\/b> on line .*<\/b>
*/ /*EXPECT_METRICS @@ -136,6 +137,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + header('Content-Type: text/html'); header('Content-Type: application/json'); @@ -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(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_exception_non_web.php b/tests/integration/api/error_group_callback/test_error_group_callback_exception_non_web.php index c369f998c..56ed9ef17 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_exception_non_web.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_exception_non_web.php @@ -10,6 +10,7 @@ /*EXPECT_REGEX +ok - callback registered request_uri => path => test_error_group_callback_exception_non_web.php method => @@ -18,7 +19,7 @@ klass => Exception message => Sample Exception file => .*test_error_group_callback_exception_non_web.php -stack => \[" in alpha called at .*test_error_group_callback_exception_non_web.php \(136\)"\] +stack => \[" in alpha called at .*test_error_group_callback_exception_non_web.php \(.*\)"\] */ /*EXPECT_METRICS @@ -110,6 +111,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -131,6 +134,8 @@ function alpha() return $fingerprint; }; -newrelic_set_error_group_callback($callback); +$result = newrelic_set_error_group_callback($callback); + +tap_assert($result, "callback registered"); alpha(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_exception_web.php b/tests/integration/api/error_group_callback/test_error_group_callback_exception_web.php index 8ebe49144..0716b9102 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_exception_web.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_exception_web.php @@ -14,6 +14,7 @@ */ /*EXPECT_REGEX +ok - callback registered request_uri => \/test_error_group_callback_exception_web.php\?foo=1&bar=2 path => .*test_error_group_callback_exception_web.php method => GET @@ -22,7 +23,7 @@ klass => Exception message => Sample Exception file => .*test_error_group_callback_exception_web.php -stack => \[" in alpha called at .*test_error_group_callback_exception_web.php \(163\)"\] +stack => \[" in alpha called at .*test_error_group_callback_exception_web.php \(.*\)"\] */ /*EXPECT_METRICS @@ -134,6 +135,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + header('Content-Type: text/html'); header('Content-Type: application/json'); @@ -158,6 +161,8 @@ function alpha() return $fingerprint; }; -newrelic_set_error_group_callback($callback); +$result = newrelic_set_error_group_callback($callback); + +tap_assert($result, "callback registered"); alpha(); diff --git a/tests/integration/api/error_group_callback/test_error_group_callback_max_string_len.php b/tests/integration/api/error_group_callback/test_error_group_callback_max_string_len.php index 510e9bfae..f263cddee 100644 --- a/tests/integration/api/error_group_callback/test_error_group_callback_max_string_len.php +++ b/tests/integration/api/error_group_callback/test_error_group_callback_max_string_len.php @@ -13,6 +13,7 @@ /*EXPECT_REGEX +ok - callback registered request_uri => path => test_error_group_callback_max_string_len.php method => @@ -21,7 +22,7 @@ klass => Exception message => Sample Exception file => .*test_error_group_callback_max_string_len.php -stack => \[" in alpha called at .*test_error_group_callback_max_string_len.php \(139\)"\] +stack => \[" in alpha called at .*test_error_group_callback_max_string_len.php \(.*\)"\] */ /*EXPECT_METRICS @@ -113,6 +114,8 @@ ] */ +require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php'); + function alpha() { newrelic_notice_error(new Exception('Sample Exception')); @@ -134,6 +137,8 @@ function alpha() return $fingerprint; }; -newrelic_set_error_group_callback($callback); +$result = newrelic_set_error_group_callback($callback); + +tap_assert($result, "callback registered"); alpha();