Skip to content

Commit 16b2e92

Browse files
committed
enhance mysqli tests
Test slowsql functionality when mysqldb is accessed via socket.
1 parent c563658 commit 16b2e92

File tree

2 files changed

+298
-0
lines changed

2 files changed

+298
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should generate explain plans when connections are made with
9+
mysqli_connect() when connecting to the database via socket.
10+
*/
11+
12+
/*SKIPIF
13+
<?php require("skipif.inc");
14+
*/
15+
16+
/*INI
17+
error_reporting = E_ALL & ~E_DEPRECATED
18+
newrelic.transaction_tracer.explain_enabled = true
19+
newrelic.transaction_tracer.explain_threshold = 0
20+
newrelic.transaction_tracer.record_sql = obfuscated
21+
*/
22+
23+
/*EXPECT
24+
STATISTICS
25+
*/
26+
27+
/*EXPECT_METRICS
28+
[
29+
"?? agent run id",
30+
"?? start time",
31+
"?? stop time",
32+
[
33+
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
34+
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]],
35+
[{"name":"Datastore/all"}, [1, "??", "??", "??", "??", "??"]],
36+
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
37+
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
38+
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
39+
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
40+
[{"name":"Datastore/statement/MySQL/tables/select",
41+
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
42+
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
43+
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
44+
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
45+
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
46+
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
47+
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
48+
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
49+
[{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]]
50+
]
51+
]
52+
*/
53+
54+
55+
56+
/*EXPECT_SLOW_SQLS
57+
[
58+
[
59+
[
60+
"OtherTransaction/php__FILE__",
61+
"<unknown>",
62+
"?? SQL ID",
63+
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
64+
"Datastore/statement/MySQL/tables/select",
65+
1,
66+
"?? total time",
67+
"?? min time",
68+
"?? max time",
69+
{
70+
"explain_plan": [
71+
[
72+
"id",
73+
"select_type",
74+
"table",
75+
"type",
76+
"possible_keys",
77+
"key",
78+
"key_len",
79+
"ref",
80+
"rows",
81+
"Extra"
82+
],
83+
[
84+
[
85+
1,
86+
"SIMPLE",
87+
"tables",
88+
"ALL",
89+
null,
90+
"TABLE_NAME",
91+
null,
92+
null,
93+
null,
94+
"Using where; Skip_open_table; Scanned 1 database"
95+
]
96+
]
97+
],
98+
"backtrace": [
99+
" in mysqli_stmt_execute called at __FILE__ (??)",
100+
" in test_prepare called at __FILE__ (??)"
101+
]
102+
}
103+
]
104+
]
105+
]
106+
*/
107+
108+
/*EXPECT_TRACED_ERRORS
109+
null
110+
*/
111+
112+
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php');
113+
114+
function test_prepare($link)
115+
{
116+
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";
117+
118+
$stmt = mysqli_prepare($link, $query);
119+
if (FALSE === $stmt) {
120+
echo mysqli_error($link) . "\n";
121+
return;
122+
}
123+
124+
if (FALSE === mysqli_stmt_execute($stmt)) {
125+
echo mysqli_stmt_error($stmt) . "\n";
126+
return;
127+
}
128+
129+
if (FALSE === mysqli_stmt_bind_result($stmt, $value)) {
130+
echo mysqli_stmt_error($stmt) . "\n";
131+
return;
132+
}
133+
134+
while (mysqli_stmt_fetch($stmt)) {
135+
echo $value . "\n";
136+
}
137+
138+
mysqli_stmt_close($stmt);
139+
}
140+
141+
$link = mysqli_connect('localhost', $MYSQL_USER, $MYSQL_PASSWD, $MYSQL_DB, null, $MYSQL_SOCKET);
142+
if (mysqli_connect_errno()) {
143+
echo mysqli_connect_error() . "\n";
144+
exit(1);
145+
}
146+
147+
test_prepare($link);
148+
mysqli_close($link);
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should generate explain plans when connections are made with new
9+
mysqli() when connecting to the database via socket.
10+
*/
11+
12+
/*SKIPIF
13+
<?php
14+
require("skipif.inc");
15+
*/
16+
17+
/*INI
18+
error_reporting = E_ALL & ~E_DEPRECATED
19+
newrelic.transaction_tracer.explain_enabled = true
20+
newrelic.transaction_tracer.explain_threshold = 0
21+
newrelic.transaction_tracer.record_sql = obfuscated
22+
*/
23+
24+
/*EXPECT
25+
STATISTICS
26+
*/
27+
28+
/*EXPECT_METRICS
29+
[
30+
"?? agent run id",
31+
"?? start time",
32+
"?? stop time",
33+
[
34+
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
35+
[{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]],
36+
[{"name":"Datastore/all"}, [1, "??", "??", "??", "??", "??"]],
37+
[{"name":"Datastore/allOther"}, [1, "??", "??", "??", "??", "??"]],
38+
[{"name":"Datastore/MySQL/all"}, [1, "??", "??", "??", "??", "??"]],
39+
[{"name":"Datastore/MySQL/allOther"}, [1, "??", "??", "??", "??", "??"]],
40+
[{"name":"Datastore/statement/MySQL/tables/select"}, [1, "??", "??", "??", "??", "??"]],
41+
[{"name":"Datastore/statement/MySQL/tables/select",
42+
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
43+
[{"name":"Datastore/operation/MySQL/select"}, [1, "??", "??", "??", "??", "??"]],
44+
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
45+
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
46+
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
47+
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
48+
[{"name":"Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
49+
[{"name":"Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
50+
[{"name":"Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]]
51+
]
52+
]
53+
*/
54+
55+
56+
57+
/*EXPECT_SLOW_SQLS
58+
[
59+
[
60+
[
61+
"OtherTransaction/php__FILE__",
62+
"<unknown>",
63+
"?? SQL ID",
64+
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?",
65+
"Datastore/statement/MySQL/tables/select",
66+
1,
67+
"?? total time",
68+
"?? min time",
69+
"?? max time",
70+
{
71+
"explain_plan": [
72+
[
73+
"id",
74+
"select_type",
75+
"table",
76+
"type",
77+
"possible_keys",
78+
"key",
79+
"key_len",
80+
"ref",
81+
"rows",
82+
"Extra"
83+
],
84+
[
85+
[
86+
1,
87+
"SIMPLE",
88+
"tables",
89+
"ALL",
90+
null,
91+
"TABLE_NAME",
92+
null,
93+
null,
94+
null,
95+
"Using where; Skip_open_table; Scanned 1 database"
96+
]
97+
]
98+
],
99+
"backtrace": [
100+
" in mysqli_stmt_execute called at __FILE__ (??)",
101+
" in test_prepare called at __FILE__ (??)"
102+
]
103+
}
104+
]
105+
]
106+
]
107+
*/
108+
109+
/*EXPECT_TRACED_ERRORS
110+
null
111+
*/
112+
113+
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php');
114+
115+
function test_prepare($link)
116+
{
117+
118+
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name='STATISTICS'";
119+
120+
$stmt = mysqli_prepare($link, $query);
121+
if (FALSE === $stmt) {
122+
echo mysqli_error($link) . "\n";
123+
return;
124+
}
125+
126+
if (FALSE === mysqli_stmt_execute($stmt)) {
127+
echo mysqli_stmt_error($stmt) . "\n";
128+
return;
129+
}
130+
131+
if (FALSE === mysqli_stmt_bind_result($stmt, $value)) {
132+
echo mysqli_stmt_error($stmt) . "\n";
133+
return;
134+
}
135+
136+
while (mysqli_stmt_fetch($stmt)) {
137+
echo $value . "\n";
138+
}
139+
140+
mysqli_stmt_close($stmt);
141+
}
142+
143+
$link = new mysqli('localhost', $MYSQL_USER, $MYSQL_PASSWD, $MYSQL_DB, null, $MYSQL_SOCKET);
144+
if (mysqli_connect_errno()) {
145+
echo mysqli_connect_error() . "\n";
146+
exit(1);
147+
}
148+
149+
test_prepare($link);
150+
mysqli_close($link);

0 commit comments

Comments
 (0)