events_logs_tests.test 4.36 KB
Newer Older
1 2 3
# Can't test with embedded server that doesn't support grants
-- source include/not_embedded.inc

4 5
CREATE DATABASE IF NOT EXISTS events_test;
USE events_test;
andrey@lmy004's avatar
andrey@lmy004 committed
6 7 8 9 10 11 12 13 14
--echo "We use procedure here because its statements won't be logged into the general log"
--echo "If we had used normal select that are logged in different ways depending on whether"
--echo "the test suite is run in normal mode or with --ps-protocol"
delimiter |;
CREATE procedure select_general_log()
BEGIN
  SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%';
END|
delimiter ;|
15
--echo "Check General Query Log"
16
--replace_column 1 USER_HOST
17
CALL select_general_log();
18
SET GLOBAL event_scheduler=on;
19 20
TRUNCATE mysql.general_log;
CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala', SLEEP(1) FROM DUAL;
21
--echo "Wait the scheduler to start"
22 23
--sleep 1.5
--echo "Should see 2 rows - the 'SELECT' is in the middle. The other two are selects from general_log"
24
--replace_column 1 USER_HOST
25
CALL select_general_log();
andrey@lmy004's avatar
andrey@lmy004 committed
26
DROP PROCEDURE select_general_log;
27
DROP EVENT log_general;
28
SET GLOBAL event_scheduler=off;
29 30

--echo "Check slow query log"
andrey@lmy004's avatar
andrey@lmy004 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
--disable_query_log
DELIMITER |;
CREATE FUNCTION get_value()
  returns INT
  deterministic
BEGIN
  DECLARE var_name CHAR(255);
  DECLARE var_val INT;
  DECLARE done INT DEFAULT 0;
  DECLARE cur1 CURSOR FOR SHOW GLOBAL VARIABLES LIKE 'long_query_time';
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
  OPEN cur1;
  FETCH cur1 INTO var_name, var_val;
  CLOSE cur1;
  RETURN var_val;
end|
DELIMITER ;|
--enable_query_log
--echo "Save the values"
SET @old_global_long_query_time:=(select get_value());
SET @old_session_long_query_time:=@@long_query_time;
SHOW VARIABLES LIKE 'log_slow_queries';
DROP FUNCTION get_value;
54 55
--echo "Make it quite long"
SET SESSION long_query_time=300;
andrey@lmy004's avatar
andrey@lmy004 committed
56
TRUNCATE mysql.slow_log;
57
--replace_column 1 USER_HOST
andrey@lmy004's avatar
andrey@lmy004 committed
58 59 60
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
--echo "Set new values"
SET GLOBAL long_query_time=4;
61
SET SESSION long_query_time=1;
andrey@lmy004's avatar
andrey@lmy004 committed
62
--echo "Check that logging is working"
63
SELECT SLEEP(2);
64
--replace_column 1 USER_HOST 2 SLEEPVAL
andrey@lmy004's avatar
andrey@lmy004 committed
65
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
66 67
SET SESSION long_query_time=300;
--echo "Make it quite long"
andrey@lmy004's avatar
andrey@lmy004 committed
68 69
TRUNCATE mysql.slow_log;
CREATE TABLE slow_event_test (slo_val tinyint, val tinyint);
70
SET SESSION long_query_time=1;
andrey@lmy004's avatar
andrey@lmy004 committed
71 72
--echo "This won't go to the slow log"
SELECT * FROM slow_event_test;
73
SET SESSION long_query_time=1;
74
SET GLOBAL event_scheduler=on;
75
SET GLOBAL long_query_time=20;
76
CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(1.5);
andrey@lmy004's avatar
andrey@lmy004 committed
77
--echo "Sleep some more time than the actual event run will take"
78
--sleep 2
79
SHOW VARIABLES LIKE 'event_scheduler';
andrey@lmy004's avatar
andrey@lmy004 committed
80 81
--echo "Check our table. Should see 1 row"
SELECT * FROM slow_event_test;
82 83
--echo "Check slow log. Should not see anything because 1.5 is under the threshold of 20 for GLOBAL, though over SESSION which is 1"
--echo "This should show that the GLOBAL value is regarded and not the SESSION one of the current connection"
andrey@lmy004's avatar
andrey@lmy004 committed
84
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
85
--echo "Another test to show that GLOBAL is regarded and not SESSION."
andrey@lmy004's avatar
andrey@lmy004 committed
86 87
--echo "This should go to the slow log"
SET SESSION long_query_time=10;
88
DROP EVENT long_event;
89 90
SET GLOBAL long_query_time=1;
CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2);
andrey@lmy004's avatar
andrey@lmy004 committed
91
--echo "Sleep some more time than the actual event run will take"
92 93 94
let $wait_timeout= 30;
let $wait_condition= SELECT COUNT(*) = 1 FROM mysql.slow_log; 
--source include/wait_condition.inc
andrey@lmy004's avatar
andrey@lmy004 committed
95 96
--echo "Check our table. Should see 2 rows"
SELECT * FROM slow_event_test;
97
--echo "Check slow log. Should see 1 row because 2 is over the threshold of 1 for GLOBAL, though under SESSION which is 10"
98
--replace_column 1 USER_HOST 2 SLEEPVAL
andrey@lmy004's avatar
andrey@lmy004 committed
99
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
100
DROP EVENT long_event2;
101 102
--echo "Make it quite long"
SET SESSION long_query_time=300;
andrey@lmy004's avatar
andrey@lmy004 committed
103 104
TRUNCATE mysql.slow_log;
DROP TABLE slow_event_test;
105 106
SET GLOBAL  long_query_time =@old_global_long_query_time;
SET SESSION long_query_time =@old_session_long_query_time; 
andrey@lmy004's avatar
andrey@lmy004 committed
107

108
DROP DATABASE events_test;
109

andrey@whirlpool.mysql.com's avatar
andrey@whirlpool.mysql.com committed
110

111
SET GLOBAL event_scheduler=off;
andrey@whirlpool.mysql.com's avatar
andrey@whirlpool.mysql.com committed
112 113 114 115 116

let $wait_condition=
  select count(*) = 0 from information_schema.processlist
  where db='events_test' and command = 'Connect' and user=current_user();
--source include/wait_condition.inc