| 1 |
## Script test_session_reset.inc |
| 2 |
# |
| 3 |
# Extracted queries form 'session_reset.test' that |
| 4 |
# it can be executed multiple times, with different |
| 5 |
# mysqlxtest configuration. |
| 6 |
# |
| 7 |
# Usage: |
| 8 |
# |
| 9 |
# [--let $param_mysqlxtest="cmd line args"|] |
| 10 |
# --source test_session_reset.inc |
| 11 |
# |
| 12 |
|
| 13 |
|
| 14 |
## Test starts here |
| 15 |
--write_file $MYSQL_TMP_DIR/session_reset.xpl |
| 16 |
-->import mysqlx_session.macro |
| 17 |
|
| 18 |
-->title =Session reset (%SESSION_CLOSE_SCENARIO%) |
| 19 |
|
| 20 |
#####Basic scenario: |
| 21 |
|
| 22 |
-->stmtadmin list_clients |
| 23 |
-->recvtovar %EXPECT_SESSION_ID% sql_session |
| 24 |
-->stmtadmin list_clients |
| 25 |
-->recvtovar %EXPECT_CLIENT_ID% client_id |
| 26 |
|
| 27 |
|
| 28 |
#1) Reset session |
| 29 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 30 |
-->recvok |
| 31 |
|
| 32 |
|
| 33 |
#2) Log back |
| 34 |
-->login x_root |
| 35 |
|
| 36 |
#3) Execute query |
| 37 |
Mysqlx.Sql.StmtExecute { |
| 38 |
stmt: "select 1.1" |
| 39 |
} |
| 40 |
-->recvresult |
| 41 |
|
| 42 |
#4) Check sql session id change |
| 43 |
-->stmtadmin list_clients |
| 44 |
-->recvtovar %CURRENT_SESSION_ID% sql_session |
| 45 |
-->assert_ne %EXPECT_SESSION_ID% %CURRENT_SESSION_ID% |
| 46 |
|
| 47 |
#5) Check client id not change |
| 48 |
-->stmtadmin list_clients |
| 49 |
-->recvtovar %CURRENT_CLIENT_ID% client_id |
| 50 |
-->assert_eq %EXPECT_CLIENT_ID% %CURRENT_CLIENT_ID% |
| 51 |
|
| 52 |
##### Check the pipelining: |
| 53 |
#1) Pipeline some queries |
| 54 |
Mysqlx.Sql.StmtExecute { |
| 55 |
stmt: "select 2.1" |
| 56 |
} |
| 57 |
|
| 58 |
Mysqlx.Sql.StmtExecute { |
| 59 |
stmt: "select 2.2" |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
#2) Reset session |
| 64 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 65 |
|
| 66 |
|
| 67 |
#3) Receive messages from queries preceeding Reset |
| 68 |
-->recvresult |
| 69 |
-->recvresult |
| 70 |
-->recvok |
| 71 |
|
| 72 |
-->login x_root |
| 73 |
|
| 74 |
|
| 75 |
######## Expect error and server disconnect trying to execute query after the session reset |
| 76 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 77 |
-->recvok |
| 78 |
|
| 79 |
Mysqlx.Sql.StmtExecute { |
| 80 |
stmt: "select 3.1" |
| 81 |
} |
| 82 |
-->recv |
| 83 |
|
| 84 |
|
| 85 |
##### Ensure that a session after reset is not the same session as from before the reset |
| 86 |
-->newsession foo |
| 87 |
|
| 88 |
-->sql |
| 89 |
set @secret = 12345; |
| 90 |
-->endsql |
| 91 |
|
| 92 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 93 |
-->recvok |
| 94 |
|
| 95 |
-->login x_root |
| 96 |
|
| 97 |
-->sql |
| 98 |
select IF(@secret is NULL, 'OK', 'FAIL'); |
| 99 |
-->endsql |
| 100 |
-->closesession |
| 101 |
|
| 102 |
|
| 103 |
##### Ensure that a global variable after reset is the same as before the reset |
| 104 |
-->newsession foobar |
| 105 |
|
| 106 |
-->sql |
| 107 |
set global max_connections = 1234 |
| 108 |
-->endsql |
| 109 |
|
| 110 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 111 |
-->recvok |
| 112 |
|
| 113 |
-->login x_root |
| 114 |
|
| 115 |
-->sql |
| 116 |
select IF(@@global.max_connections = 1234, 'OK', 'FAIL'); |
| 117 |
set @@global.max_connections = default; |
| 118 |
-->endsql |
| 119 |
-->closesession |
| 120 |
|
| 121 |
### Ensure that a session expect block is reset |
| 122 |
#TODO: this is not expected behavior; need to be fix |
| 123 |
|
| 124 |
-->newsession bar |
| 125 |
Mysqlx.Expect.Open { |
| 126 |
cond { |
| 127 |
condition_key: 1 |
| 128 |
} |
| 129 |
} |
| 130 |
-->recvok |
| 131 |
|
| 132 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 133 |
-->recvok |
| 134 |
|
| 135 |
-->login x_root |
| 136 |
Mysqlx.Expect.Close { |
| 137 |
} |
| 138 |
-->recverror ER_X_EXPECT_NOT_OPEN |
| 139 |
|
| 140 |
EOF |
| 141 |
|
| 142 |
--write_file $MYSQL_TMP_DIR/session_reset_single_frame.xpl |
| 143 |
-->macro Session_reset_empty |
| 144 |
-->binparse %RST% Mysqlx.Session.Reset { |
| 145 |
} |
| 146 |
-->endmacro |
| 147 |
|
| 148 |
-->macro Session_reset |
| 149 |
-->binparse %RST% Mysqlx.Session.Reset { |
| 150 |
keep_open:false |
| 151 |
} |
| 152 |
-->endmacro |
| 153 |
|
| 154 |
-->macro Session_close |
| 155 |
-->binparse %RST% Mysqlx.Session.Close { |
| 156 |
} |
| 157 |
-->endmacro |
| 158 |
|
| 159 |
-->title =Session reset single frame (%SESSION_CLOSE_SCENARIO%) |
| 160 |
|
| 161 |
-->binparse %SEL1% Mysqlx.Sql.StmtExecute { |
| 162 |
stmt: "select 2.1" |
| 163 |
} |
| 164 |
|
| 165 |
-->binparse %SEL2% Mysqlx.Sql.StmtExecute { |
| 166 |
stmt: "select 2.2" |
| 167 |
} |
| 168 |
|
| 169 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 170 |
|
| 171 |
-->binsend %SEL1%%RST%%SEL2% |
| 172 |
|
| 173 |
-->recvresult |
| 174 |
-->recv |
| 175 |
-->recv |
| 176 |
-->closesession abort |
| 177 |
EOF |
| 178 |
|
| 179 |
|
| 180 |
--write_file $MYSQL_TMP_DIR/session_reset_prepared_stmt.xpl |
| 181 |
-->title =Session reset prepared stmt (%SESSION_CLOSE_SCENARIO%) |
| 182 |
-->import assert_variable.macro |
| 183 |
-->import mysqlx_session.macro |
| 184 |
|
| 185 |
|
| 186 |
## WL#9270 - ensure that session reset deallocates MySQL Servers |
| 187 |
## prepared statements allocated by Mysqlx.Prepare messages |
| 188 |
|
| 189 |
Mysqlx.Prepare.Prepare { |
| 190 |
stmt_id: 2 |
| 191 |
stmt: { |
| 192 |
type: STMT |
| 193 |
stmt_execute: { |
| 194 |
stmt: "select 2" |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
-->recvok |
| 199 |
|
| 200 |
Mysqlx.Cursor.Open { |
| 201 |
cursor_id: 3 |
| 202 |
stmt: { |
| 203 |
type: PREPARE_EXECUTE |
| 204 |
prepare_execute { |
| 205 |
stmt_id: 2 |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
-->recvresult |
| 210 |
|
| 211 |
-->callmacro Assert_status_variable Prepared_stmt_count 1 |
| 212 |
|
| 213 |
-->callmacro %SESSION_CLOSE_SCENARIO% |
| 214 |
-->recvok |
| 215 |
|
| 216 |
-->login x_root |
| 217 |
|
| 218 |
-->callmacro Assert_status_variable Prepared_stmt_count 0 |
| 219 |
|
| 220 |
Mysqlx.Prepare.Execute { |
| 221 |
stmt_id: 2 |
| 222 |
} |
| 223 |
-->expecterror ER_X_BAD_STATEMENT_ID |
| 224 |
-->recvresult |
| 225 |
|
| 226 |
Mysqlx.Cursor.Fetch { |
| 227 |
cursor_id: 3 |
| 228 |
} |
| 229 |
-->expecterror ER_X_BAD_CURSOR_ID |
| 230 |
-->recvresult |
| 231 |
|
| 232 |
EOF |
| 233 |
|
| 234 |
echo ## 1. Execute Reset using basic scenarios; |
| 235 |
echo # a. verify that reset without args removes current session; |
| 236 |
echo # b. verify that reset with keep_open=false removes current session; |
| 237 |
echo # c. verify that close removes current session; |
| 238 |
echo ## 2. Execute Reset with pipelined stmt-execute; |
| 239 |
echo # a. verify that reset without args removes current session; |
| 240 |
echo # b. verify that reset with keep_open=false removes current session; |
| 241 |
echo # c. verify that close removes current session; |
| 242 |
echo ## 3. Execute Reset and check that prepared-stmts are removed; |
| 243 |
echo # a. verify that reset without args removes current session and prepared-statemtents; |
| 244 |
echo # b. verify that reset with keep_open=false removes current session and prepared-statemtents; |
| 245 |
echo # c. verify that close removes current session and prepared-statemtents; |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
--echo |
| 250 |
--echo ## 1.a |
| 251 |
--echo # |
| 252 |
exec $MYSQLXTEST $PARAM $param_mysqlxtest |
| 253 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset_empty |
| 254 |
--file=$MYSQL_TMP_DIR/session_reset.xpl 2>&1; |
| 255 |
--echo |
| 256 |
--echo ## 1.b |
| 257 |
--echo # |
| 258 |
exec $MYSQLXTEST $param_mysqlxtest |
| 259 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset |
| 260 |
--file=$MYSQL_TMP_DIR/session_reset.xpl 2>&1; |
| 261 |
--echo |
| 262 |
--echo ## 1.c |
| 263 |
--echo # |
| 264 |
exec $MYSQLXTEST $param_mysqlxtest |
| 265 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_close |
| 266 |
--file=$MYSQL_TMP_DIR/session_reset.xpl 2>&1; |
| 267 |
|
| 268 |
|
| 269 |
--echo |
| 270 |
--echo ## 2.a |
| 271 |
--echo # |
| 272 |
exec $MYSQLXTEST $param_mysqlxtest |
| 273 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset_empty |
| 274 |
--file=$MYSQL_TMP_DIR/session_reset_single_frame.xpl 2>&1; |
| 275 |
--echo |
| 276 |
--echo ## 2.b |
| 277 |
--echo # |
| 278 |
exec $MYSQLXTEST $param_mysqlxtest |
| 279 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset |
| 280 |
--file=$MYSQL_TMP_DIR/session_reset_single_frame.xpl 2>&1; |
| 281 |
--echo |
| 282 |
--echo ## 2.c |
| 283 |
--echo # |
| 284 |
exec $MYSQLXTEST $param_mysqlxtest |
| 285 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_close |
| 286 |
--file=$MYSQL_TMP_DIR/session_reset_single_frame.xpl 2>&1; |
| 287 |
|
| 288 |
|
| 289 |
--echo |
| 290 |
--echo ## 3.a |
| 291 |
--echo # |
| 292 |
exec $MYSQLXTEST $param_mysqlxtest |
| 293 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset_empty |
| 294 |
--file=$MYSQL_TMP_DIR/session_reset_prepared_stmt.xpl; |
| 295 |
--echo |
| 296 |
--echo ## 3.b |
| 297 |
--echo # |
| 298 |
exec $MYSQLXTEST $param_mysqlxtest |
| 299 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_reset |
| 300 |
--file=$MYSQL_TMP_DIR/session_reset_prepared_stmt.xpl; |
| 301 |
--echo |
| 302 |
--echo ## 3.c |
| 303 |
--echo # |
| 304 |
exec $MYSQLXTEST $param_mysqlxtest |
| 305 |
-ux_root --password='' -v%SESSION_CLOSE_SCENARIO%=Session_close |
| 306 |
--file=$MYSQL_TMP_DIR/session_reset_prepared_stmt.xpl; |
| 307 |
|
| 308 |
## Cleanup |
| 309 |
--remove_file $MYSQL_TMP_DIR/session_reset.xpl |
| 310 |
--remove_file $MYSQL_TMP_DIR/session_reset_single_frame.xpl |
| 311 |
--remove_file $MYSQL_TMP_DIR/session_reset_prepared_stmt.xpl |