Debian Codegraph @

mysql-test/suite/perfschema/t/socket_connect.test

raw
1 #
2 # Check the handling of TCP/IP connections in the performance_schema socket
3 # instance tables
4 #
5 #==============================================================================
6
7 --source include/not_embedded.inc
8 --source include/have_perfschema.inc
9 --source ../include/wait_for_pfs_thread_count.inc
10
11 # Set this to enable debugging output
12 let $my_socket_debug_dbug=0;
13
14 --echo #==============================================================================
15 --echo # Establish the level of IPV6 support
16 --echo #==============================================================================
17 --source ../include/socket_ipv6.inc
18
19 --disable_cursor_protocol
20 --echo #==============================================================================
21 --echo # Get hostname, port number
22 --echo #==============================================================================
23 SELECT @@hostname INTO @MY_HOSTNAME;
24 SELECT @@port INTO @MY_MASTER_PORT;
25
26 if ($my_socket_debug)
27 {
28 SELECT @MY_HOSTNAME AS 'Hostname';
29 SELECT @MY_MASTER_PORT AS 'Master Port';
30 }
31 #==============================================================================
32 # Utility queries
33 #==============================================================================
34 let $count_client_connections=
35 SELECT COUNT(*) INTO @my_client_connections
36 FROM performance_schema.socket_instances
37 WHERE EVENT_NAME LIKE "%client_connection%";
38
39 let $get_thread_id=
40 SELECT THREAD_ID INTO @my_thread_id
41 FROM performance_schema.threads
42 WHERE PROCESSLIST_ID = CONNECTION_ID();
43
44 let $get_object_instance_begin=
45 SELECT OBJECT_INSTANCE_BEGIN INTO @my_object_instance_begin
46 FROM performance_schema.socket_instances
47 WHERE THREAD_ID = @my_thread_id;
48
49 let $get_port=
50 SELECT PORT INTO @my_port
51 FROM performance_schema.socket_instances
52 WHERE THREAD_ID = @my_thread_id;
53
54 let $ip_localhost=
55 (IP LIKE '%127.0.0.1' OR IP LIKE '%::1');
56
57 --echo #==============================================================================
58 --echo # 1.0 Get the default connection object_instance_begin, thread id and verify
59 --echo # the expected number of client connections.
60 --echo #==============================================================================
61 --echo #
62 --echo # 1.1 Confirm only one client connection
63 --echo #
64 eval $count_client_connections;
65
66 if (`SELECT @my_client_connections != 1`)
67 {
68 --echo # There should be one client connection
69 SELECT * FROM performance_schema.socket_instances;
70 --echo # abort
71 exit;
72 }
73
74 --echo #
75 --echo # 1.2 Get the default THREAD_ID;
76 --echo #
77 eval $get_thread_id;
78 let $default_thread_id= `SELECT @my_thread_id`;
79
80 --echo #
81 --echo # 1.3 Get the default OBJECT_INSTANCE_BEGIN
82 --echo #
83 eval $get_object_instance_begin;
84 let $default_object_instance_begin= `SELECT @my_object_instance_begin`;
85 --disable_query_log
86 SELECT @my_object_instance_begin INTO @default_object_instance_begin;
87 --enable_query_log
88
89 if ($my_socket_debug)
90 {
91 --echo # Default object instance begin = $default_object_instance_begin
92 --echo # Default thread id = $default_thread_id
93 }
94
95 --echo #==============================================================================
96 --echo # 2.0 ESTABLISH TCP/IP CONNECTION 1
97 --echo # Connect with IP = localhost (127.0.0.1 or ::1)
98 --echo #==============================================================================
99 --disable_query_log
100 --connect (con1,$my_localhost,root,,test,,$MASTER_MYPORT)
101 --enable_query_log
102
103 --echo #
104 --echo # 2.1 Get the connection thread id
105 --echo #
106 eval $get_thread_id;
107
108 --echo #
109 --echo # 2.2 Get the connection object instance begin
110 --echo #
111 eval $get_object_instance_begin;
112
113 --echo #
114 --echo # 2.3 Get the connection port
115 --echo #
116 eval $get_port;
117
118 --disable_query_log
119 SELECT @my_thread_id INTO @con1_thread_id;
120 SELECT @my_port INTO @con1_port;
121 SELECT @my_object_instance_begin INTO @con1_object_id;
122 let $con1_thread_id= `SELECT @con1_thread_id`;
123 let $con1_port= `SELECT @con1_port`;
124 let $con1_object_id= `SELECT @con1_object_id`;
125 let $con1_name1= "127.0.0.1:$con1_port";
126 let $con1_name2= "::1:$con1_port";
127 --enable_query_log
128
129 if ($my_socket_debug)
130 {
131 --echo # Con1 thread id = $con1_thread_id
132 --echo # Con1 object_id = $con1_object_id
133 --echo # Con1 port = $con1_port
134 --echo # Con1 name1 = $con1_name1
135 --echo # Con1 name2 = $con1_name2
136 }
137
138 --echo #
139 --echo # 2.4 Verify that the connection is 127.0.0.1 or ::1
140 --echo #
141 eval SELECT COUNT(*) = 1 AS 'Expect 1'
142 FROM performance_schema.socket_instances
143 WHERE EVENT_NAME LIKE '%client_connection%'
144 AND $ip_localhost
145 AND PORT= @con1_port
146 AND OBJECT_INSTANCE_BEGIN= @con1_object_id;
147
148 --echo #
149 --echo # 2.5 Verify that the same connection is in the summary instance table
150 --echo #
151 eval SELECT COUNT(*) = 1 AS 'Expect 1'
152 FROM performance_schema.socket_summary_by_instance
153 WHERE EVENT_NAME LIKE '%client_connection%'
154 AND OBJECT_INSTANCE_BEGIN= @con1_object_id;
155
156 --echo #
157 --echo # Switch to connection default
158 --echo #
159 --connection default
160
161 --echo #==============================================================================
162 --echo # 3.0 ESTABLISH TCP/IP CONNECTION 2
163 --echo # Connect with IP = localhost (127.0.0.1 or ::1)
164 --echo #==============================================================================
165 --disable_query_log
166 --connect (con2,$my_localhost,root,,test,,$MASTER_MYPORT)
167 --enable_query_log
168
169 --echo #
170 --echo # 3.1 Get the connection thread id
171 --echo #
172 eval $get_thread_id;
173
174 --echo #
175 --echo # 3.2 Get the connection object instance begin
176 --echo #
177 eval $get_object_instance_begin;
178
179 --echo #
180 --echo # 3.3 Get the connection port
181 --echo #
182 eval $get_port;
183
184 --disable_query_log
185 SELECT @my_thread_id INTO @con2_thread_id;
186 SELECT @my_port INTO @con2_port;
187 SELECT @my_object_instance_begin INTO @con2_object_id;
188 let $con2_thread_id= `SELECT @con2_thread_id`;
189 let $con2_port= `SELECT @con2_port`;
190 let $con2_object_id= `SELECT @con2_object_id`;
191 let $con2_name1= "127.0.0.1:$con2_port";
192 let $con2_name2= "::1:$con2_port";
193 --enable_query_log
194
195 if ($my_socket_debug)
196 {
197 --echo # con2 thread id = $con2_thread_id
198 --echo # con2 object_id = $con2_object_id
199 --echo # con2 port = $con2_port
200 --echo # con2 name1 = $con2_name1
201 --echo # con2 name2 = $con2_name2
202 }
203
204 --echo #
205 --echo # 3.4 Verify that the connection is 127.0.0.1 or ::1
206 --echo #
207
208 eval SELECT COUNT(*) = 1 AS 'Expect 1'
209 FROM performance_schema.socket_instances
210 WHERE EVENT_NAME LIKE '%client_connection%'
211 AND $ip_localhost
212 AND PORT= @con2_port
213 AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
214
215 --echo #
216 --echo # 3.5 Verify that the same connection is in the summary instance table
217 --echo #
218 eval SELECT COUNT(*) = 1 AS 'Expect 1'
219 FROM performance_schema.socket_summary_by_instance
220 WHERE EVENT_NAME LIKE '%client_connection%'
221 AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
222
223 --echo #
224 --echo # 3.6 Verify that the connection is 127.0.0.1 or ::1
225 --echo #
226 eval SELECT COUNT(*) = 1 AS 'Expect 1'
227 FROM performance_schema.socket_instances
228 WHERE EVENT_NAME LIKE '%client_connection%'
229 AND $ip_localhost
230 AND PORT= @con2_port
231 AND OBJECT_INSTANCE_BEGIN= @con2_object_id;
232
233 --echo #==============================================================================
234 --echo # 4.0 Verify both connections exist in the instance tables
235 --echo #==============================================================================
236 --connection default
237
238 --echo #
239 --echo # 4.1 Verify that there are two TCP/IP connections in the socket instance table
240 --echo #
241 eval SELECT COUNT(*) = 2 AS 'Expect 2'
242 FROM performance_schema.socket_instances
243 WHERE EVENT_NAME LIKE '%client_connection%'
244 AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin
245 AND $ip_localhost;
246
247 --echo #
248 --echo # 4.2 Verify that there are two TCP/IP connections in the summary instance table
249 --echo #
250 eval SELECT COUNT(*) = 2 AS 'Expect 2'
251 FROM performance_schema.socket_summary_by_instance
252 WHERE EVENT_NAME LIKE '%client_connection%'
253 AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin;
254
255 --echo #==============================================================================
256 --echo # 5.0 Drop the client connections
257 --echo #==============================================================================
258
259 --echo # 5.1 Disconnect con1
260 --connection con1
261 --disconnect con1
262 --source include/wait_until_disconnected.inc
263
264 --echo # 5.2 Disconnect con2
265 --connection con2
266 --disconnect con2
267 --source include/wait_until_disconnected.inc
268 --connection default
269
270 --echo #==============================================================================
271 --echo # 6.0 Verify sockets were removed from the instance tables
272 --echo #==============================================================================
273
274 --echo #
275 --echo # 6.1 Verify that there are no TCP/IP connections in the socket instance table
276 --echo #
277 let $wait_condition=
278 SELECT COUNT(*) = 0 AS 'Expect 0'
279 FROM performance_schema.socket_instances
280 WHERE EVENT_NAME LIKE '%client_connection%'
281 AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin
282 AND $ip_localhost;
283 --source include/wait_condition.inc
284
285 --echo #
286 --echo # 6.2 Verify that there are no TCP/IP connections in the summary instance table
287 --echo #
288 let $wait_condition=
289 SELECT COUNT(*) = 0 AS 'Expect 0'
290 FROM performance_schema.socket_summary_by_instance
291 WHERE EVENT_NAME LIKE '%client_connection%'
292 AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin;
293 --source include/wait_condition.inc
294 exit;
295 --enable_cursor_protocol