Commit 06219c2a authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-21599 - plugins.server_audit fails sporadically in buildbot

Fixed a couple of race conditions in the test case to ensure stable order
of events. Also removed all sleeps. Test execution time is down from 18s
to 0.15s.

On disconnect audit event is triggered after control is returned to
mysqltest client. Which means mysqltest may issue more commands
concurrently before disconnect is actually logged.

Similar problem happens with regular query execution: an event is
triggered after control is returner to the client. Which may end
up with unstable order of events in different connections.

Delayed insert rows are enqueued separately and can either be combined
into single event or go as separate events. Reduced number of inserted
rows to 1 to stabilize result.

Also backported 2b3f6ab4 from 10.5.
parent d565895b
perl;
use strict;
use Time::HiRes qw(sleep);
my $search_count= $ENV{'SEARCH_COUNT'} or die "SEARCH_COUNT not set";
my $search_file= $ENV{'SEARCH_FILE'} or die "SEARCH_FILE not set";
my $wait_counter= 100; # 10 seconds
while (1)
{
my $cnt= 0;
open(FILE, $search_file) or die("Unable to open '$search_file': $!\n");
$cnt++ while (<FILE>);
close(FILE);
last if ($cnt == $search_count);
$wait_counter-- or
die "Timeout waiting for $search_count lines in $search_file\n";
sleep(0.1);
}
EOF
...@@ -32,7 +32,6 @@ show variables like 'server_audit_excl_users'; ...@@ -32,7 +32,6 @@ show variables like 'server_audit_excl_users';
Variable_name Value Variable_name Value
server_audit_excl_users server_audit_excl_users
connect con1,localhost,root,,mysql; connect con1,localhost,root,,mysql;
connection default;
disconnect con1; disconnect con1;
connect(localhost,no_such_user,,mysql,MASTER_PORT,MASTER_SOCKET); connect(localhost,no_such_user,,mysql,MASTER_PORT,MASTER_SOCKET);
connect con1,localhost,no_such_user,,mysql; connect con1,localhost,no_such_user,,mysql;
...@@ -99,7 +98,6 @@ set global server_audit_mode=1; ...@@ -99,7 +98,6 @@ set global server_audit_mode=1;
set global server_audit_events=''; set global server_audit_events='';
create database sa_db; create database sa_db;
connect con1,localhost,root,,test; connect con1,localhost,root,,test;
connection con1;
create table t1 (id2 int); create table t1 (id2 int);
insert into t1 values (1), (2); insert into t1 values (1), (2);
select * from t1; select * from t1;
...@@ -112,8 +110,8 @@ create table sa_t1(id int); ...@@ -112,8 +110,8 @@ create table sa_t1(id int);
insert into sa_t1 values (1), (2); insert into sa_t1 values (1), (2);
drop table sa_t1; drop table sa_t1;
drop database sa_db; drop database sa_db;
connection default;
disconnect con1; disconnect con1;
connection default;
create database sa_db; create database sa_db;
use sa_db; use sa_db;
CREATE USER u1 IDENTIFIED BY 'pwd-123'; CREATE USER u1 IDENTIFIED BY 'pwd-123';
...@@ -219,7 +217,7 @@ grant all on sa_db.* to user1@localhost; ...@@ -219,7 +217,7 @@ grant all on sa_db.* to user1@localhost;
connect cn1,localhost,user1,,sa_db; connect cn1,localhost,user1,,sa_db;
connection cn1; connection cn1;
create table t1(id int) engine=myisam; create table t1(id int) engine=myisam;
insert delayed into t1 values (1), (2); insert delayed into t1 values (1);
connection default; connection default;
# Waiting until INSERT DELAYED thread does the insert. # Waiting until INSERT DELAYED thread does the insert.
drop table t1; drop table t1;
......
...@@ -5,6 +5,13 @@ if (!$SERVER_AUDIT_SO) { ...@@ -5,6 +5,13 @@ if (!$SERVER_AUDIT_SO) {
skip No SERVER_AUDIT plugin; skip No SERVER_AUDIT plugin;
} }
# An unfortunate wait for check-testcase.test to complete disconnect.
let count_sessions= 1;
source include/wait_until_count_sessions.inc;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
let SEARCH_FILE= $MYSQLD_DATADIR/server_audit.log;
install plugin server_audit soname 'server_audit'; install plugin server_audit soname 'server_audit';
show variables like 'server_audit%'; show variables like 'server_audit%';
...@@ -20,18 +27,21 @@ show variables like 'server_audit_incl_users'; ...@@ -20,18 +27,21 @@ show variables like 'server_audit_incl_users';
--error ER_WRONG_VALUE_FOR_VAR --error ER_WRONG_VALUE_FOR_VAR
set global server_audit_excl_users= repeat("'root',", 10000); set global server_audit_excl_users= repeat("'root',", 10000);
show variables like 'server_audit_excl_users'; show variables like 'server_audit_excl_users';
let SEARCH_COUNT= 5;
source include/wait_for_line_count_in_file.inc;
--sleep 2
connect (con1,localhost,root,,mysql); connect (con1,localhost,root,,mysql);
connection default;
disconnect con1; disconnect con1;
--sleep 2 let SEARCH_COUNT= 7;
--sleep 2 source include/wait_for_line_count_in_file.inc;
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR --error ER_ACCESS_DENIED_ERROR
connect (con1,localhost,no_such_user,,mysql); connect (con1,localhost,no_such_user,,mysql);
let SEARCH_COUNT= 9;
source include/wait_for_line_count_in_file.inc;
connection default; connection default;
--sleep 2
set global server_audit_incl_users='odin, dva, tri'; set global server_audit_incl_users='odin, dva, tri';
create table t1 (id int); create table t1 (id int);
set global server_audit_incl_users='odin, root, dva, tri'; set global server_audit_incl_users='odin, root, dva, tri';
...@@ -61,11 +71,10 @@ show variables like 'server_audit%'; ...@@ -61,11 +71,10 @@ show variables like 'server_audit%';
set global server_audit_mode=1; set global server_audit_mode=1;
set global server_audit_events=''; set global server_audit_events='';
create database sa_db; create database sa_db;
--sleep 2 let SEARCH_COUNT= 41;
source include/wait_for_line_count_in_file.inc;
connect (con1,localhost,root,,test); connect (con1,localhost,root,,test);
connection con1;
--sleep 2
--sleep 2
create table t1 (id2 int); create table t1 (id2 int);
insert into t1 values (1), (2); insert into t1 values (1), (2);
select * from t1; select * from t1;
...@@ -75,10 +84,11 @@ create table sa_t1(id int); ...@@ -75,10 +84,11 @@ create table sa_t1(id int);
insert into sa_t1 values (1), (2); insert into sa_t1 values (1), (2);
drop table sa_t1; drop table sa_t1;
drop database sa_db; drop database sa_db;
connection default;
disconnect con1; disconnect con1;
--sleep 2 let SEARCH_COUNT= 68;
--sleep 2 source include/wait_for_line_count_in_file.inc;
connection default;
create database sa_db; create database sa_db;
use sa_db; use sa_db;
CREATE USER u1 IDENTIFIED BY 'pwd-123'; CREATE USER u1 IDENTIFIED BY 'pwd-123';
...@@ -146,10 +156,10 @@ connect (cn1,localhost,user1,,sa_db); ...@@ -146,10 +156,10 @@ connect (cn1,localhost,user1,,sa_db);
connection cn1; connection cn1;
create table t1(id int) engine=myisam; create table t1(id int) engine=myisam;
insert delayed into t1 values (1), (2); insert delayed into t1 values (1);
connection default; connection default;
--echo # Waiting until INSERT DELAYED thread does the insert. --echo # Waiting until INSERT DELAYED thread does the insert.
let $wait_condition= SELECT COUNT(*) = 2 FROM t1; let $wait_condition= SELECT COUNT(*) = 1 FROM t1;
--source include/wait_condition.inc --source include/wait_condition.inc
drop table t1; drop table t1;
...@@ -157,6 +167,9 @@ set global server_audit_logging= off; ...@@ -157,6 +167,9 @@ set global server_audit_logging= off;
set global server_audit_incl_users='root'; set global server_audit_incl_users='root';
set global server_audit_logging= on; set global server_audit_logging= on;
disconnect cn1; disconnect cn1;
let $count_sessions=1;
source include/wait_until_count_sessions.inc;
drop user user1@localhost; drop user user1@localhost;
set global server_audit_events=''; set global server_audit_events='';
...@@ -179,7 +192,6 @@ show status like 'server_audit_current_log'; ...@@ -179,7 +192,6 @@ show status like 'server_audit_current_log';
show variables like 'server_audit%'; show variables like 'server_audit%';
uninstall plugin server_audit; uninstall plugin server_audit;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
# replace the timestamp and the hostname with constant values # replace the timestamp and the hostname with constant values
--replace_regex /[0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\,[^,]*\,/TIME,HOSTNAME,/ /\,[1-9][0-9]*\,/,1,/ /\,[1-9][0-9]*/,ID/ --replace_regex /[0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\,[^,]*\,/TIME,HOSTNAME,/ /\,[1-9][0-9]*\,/,1,/ /\,[1-9][0-9]*/,ID/
cat_file $MYSQLD_DATADIR/server_audit.log; cat_file $MYSQLD_DATADIR/server_audit.log;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment