socket_connect.test 8.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#
# Check the handling of TCP/IP connections in the performance_schema socket
# instance tables
#
#==============================================================================

--source include/not_embedded.inc
--source include/have_perfschema.inc
--source ../include/wait_for_pfs_thread_count.inc

# Set this to enable debugging output
unknown's avatar
unknown committed
12
let $my_socket_debug_dbug=0;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290

--echo #==============================================================================
--echo # Establish the level of IPV6 support
--echo #==============================================================================
--source ../include/socket_ipv6.inc

--echo #==============================================================================
--echo # Get hostname, port number
--echo #==============================================================================
SELECT @@hostname INTO @MY_HOSTNAME;
SELECT @@port INTO @MY_MASTER_PORT;

if ($my_socket_debug)
{
  SELECT @MY_HOSTNAME AS 'Hostname';
  SELECT @MY_MASTER_PORT AS 'Master Port';
}
#==============================================================================
# Utility queries
#==============================================================================
let $count_client_connections=
  SELECT COUNT(*) INTO @my_client_connections
  FROM performance_schema.socket_instances
  WHERE EVENT_NAME LIKE "%client_connection%";

let $get_thread_id=
  SELECT THREAD_ID INTO @my_thread_id
  FROM performance_schema.threads
  WHERE PROCESSLIST_ID = CONNECTION_ID();

let $get_object_instance_begin=
  SELECT OBJECT_INSTANCE_BEGIN INTO @my_object_instance_begin
  FROM performance_schema.socket_instances
  WHERE THREAD_ID = @my_thread_id;

let $get_port=
  SELECT PORT INTO @my_port
  FROM performance_schema.socket_instances
  WHERE THREAD_ID = @my_thread_id;

let $ip_localhost=
  (IP LIKE '%127.0.0.1' OR IP LIKE '%::1');

--echo #==============================================================================
--echo # 1.0 Get the default connection object_instance_begin, thread id and verify
--echo #     the expected number of client connections.
--echo #==============================================================================
--echo
--echo # 1.1 Confirm only one client connection
--echo
eval $count_client_connections;

if (`SELECT @my_client_connections != 1`)
{
  --echo # There should be one client connection
  SELECT * FROM performance_schema.socket_instances;
  --echo # abort
  exit;
}

--echo
--echo # 1.2 Get the default THREAD_ID;
--echo
eval $get_thread_id;
let $default_thread_id= `SELECT @my_thread_id`;

--echo
--echo # 1.3 Get the default OBJECT_INSTANCE_BEGIN
--echo
eval $get_object_instance_begin;
let $default_object_instance_begin= `SELECT @my_object_instance_begin`;
--disable_query_log
SELECT @my_object_instance_begin INTO @default_object_instance_begin;
--enable_query_log

if ($my_socket_debug)
{
  --echo # Default object instance begin = $default_object_instance_begin
  --echo # Default thread id = $default_thread_id
}

--echo #==============================================================================
--echo # 2.0 ESTABLISH TCP/IP CONNECTION 1
--echo #     Connect with IP = localhost (127.0.0.1 or ::1)
--echo #==============================================================================
--disable_query_log
--connect (con1,$my_localhost,root,,test,,$MASTER_MYPORT)
--enable_query_log

--echo
--echo # 2.1 Get the connection thread id
--echo
eval $get_thread_id;

--echo
--echo # 2.2 Get the connection object instance begin
--echo
eval $get_object_instance_begin;

--echo
--echo # 2.3 Get the connection port
--echo
eval $get_port;

--disable_query_log
SELECT @my_thread_id INTO @con1_thread_id;
SELECT @my_port INTO @con1_port;
SELECT @my_object_instance_begin INTO @con1_object_id;
let $con1_thread_id= `SELECT @con1_thread_id`;
let $con1_port= `SELECT @con1_port`;
let $con1_object_id= `SELECT @con1_object_id`;
let $con1_name1= "127.0.0.1:$con1_port";
let $con1_name2= "::1:$con1_port";
--enable_query_log

if ($my_socket_debug)
{
  --echo # Con1 thread id = $con1_thread_id
  --echo # Con1 object_id = $con1_object_id
  --echo # Con1 port      = $con1_port
  --echo # Con1 name1     = $con1_name1
  --echo # Con1 name2     = $con1_name2
}

--echo
--echo # 2.4 Verify that the connection is 127.0.0.1 or ::1
--echo
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME LIKE '%client_connection%'
  AND $ip_localhost
  AND PORT= @con1_port
  AND OBJECT_INSTANCE_BEGIN= @con1_object_id;

--echo
--echo # 2.5 Verify that the same connection is in the summary instance table
--echo
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_summary_by_instance
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN= @con1_object_id;

--echo
--echo # Switch to connection default
--echo
--connection default

--echo #==============================================================================
--echo # 3.0 ESTABLISH TCP/IP CONNECTION 2
--echo #     Connect with IP = localhost (127.0.0.1 or ::1)
--echo #==============================================================================
--disable_query_log
--connect (con2,$my_localhost,root,,test,,$MASTER_MYPORT)
--enable_query_log

--echo
--echo # 3.1 Get the connection thread id
--echo
eval $get_thread_id;

--echo
--echo # 3.2 Get the connection object instance begin
--echo
eval $get_object_instance_begin;

--echo
--echo # 3.3 Get the connection port
--echo
eval $get_port;

--disable_query_log
SELECT @my_thread_id INTO @con2_thread_id;
SELECT @my_port INTO @con2_port;
SELECT @my_object_instance_begin INTO @con2_object_id;
let $con2_thread_id= `SELECT @con2_thread_id`;
let $con2_port= `SELECT @con2_port`;
let $con2_object_id= `SELECT @con2_object_id`;
let $con2_name1= "127.0.0.1:$con2_port";
let $con2_name2= "::1:$con2_port";
--enable_query_log

if ($my_socket_debug)
{
  --echo # con2 thread id = $con2_thread_id
  --echo # con2 object_id = $con2_object_id
  --echo # con2 port      = $con2_port
  --echo # con2 name1     = $con2_name1
  --echo # con2 name2     = $con2_name2
}

--echo
--echo # 3.4 Verify that the connection is 127.0.0.1 or ::1
--echo

eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME LIKE '%client_connection%'
  AND $ip_localhost
  AND PORT= @con2_port
  AND OBJECT_INSTANCE_BEGIN= @con2_object_id;

--echo
--echo # 3.5 Verify that the same connection is in the summary instance table
--echo
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_summary_by_instance
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN= @con2_object_id;

--echo
--echo # 3.6 Verify that the connection is 127.0.0.1 or ::1
--echo
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME LIKE '%client_connection%'
  AND $ip_localhost
  AND PORT= @con2_port
  AND OBJECT_INSTANCE_BEGIN= @con2_object_id;

--echo #==============================================================================
--echo # 4.0 Verify both connections exist in the instance tables
--echo #==============================================================================
--connection default

--echo
--echo # 4.1 Verify that there are two TCP/IP connections in the socket instance table
--echo
eval SELECT COUNT(*) = 2 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin
  AND $ip_localhost;

--echo
--echo # 4.2 Verify that there are two TCP/IP connections in the summary instance table
--echo
eval SELECT COUNT(*) = 2 AS 'Expect 1'
FROM performance_schema.socket_summary_by_instance
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin;

--echo #==============================================================================
--echo # 5.0 Drop the client connections
--echo #==============================================================================

--echo # 5.1 Disconnect con1
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc

--echo # 5.2 Disconnect con2
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection default

--echo #==============================================================================
--echo # 6.0 Verify sockets were removed from the instance tables
--echo #==============================================================================

--echo
--echo # 6.1 Verify that there are no TCP/IP connections in the socket instance table
--echo
eval SELECT COUNT(*) = 0 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin
  AND $ip_localhost;

--echo
--echo # 6.2 Verify that there are no TCP/IP connections in the summary instance table
--echo
eval SELECT COUNT(*) = 0 AS 'Expect 1'
FROM performance_schema.socket_summary_by_instance
WHERE EVENT_NAME LIKE '%client_connection%'
  AND OBJECT_INSTANCE_BEGIN <> @default_object_instance_begin;

exit;