mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / events_scheduling.test
blob5f16f8bea6a847bbb860128cb5f3a9f2d2c51433
1 # Can't test with embedded server that doesn't support events
2 -- source include/not_embedded.inc
4 CREATE DATABASE IF NOT EXISTS events_test;
5 USE events_test;
7 SET @event_scheduler=@@global.event_scheduler;
8 SET GLOBAL event_scheduler=OFF;
9 --echo Try again to make sure it's allowed
10 SET GLOBAL event_scheduler=OFF;
11 SHOW VARIABLES LIKE 'event_scheduler';
12 SET GLOBAL event_scheduler=1;
13 SHOW VARIABLES LIKE 'event_scheduler';
14 SET GLOBAL event_scheduler=0;
15 SHOW VARIABLES LIKE 'event_scheduler';
16 SET GLOBAL event_scheduler=ON;
17 --echo Try again to make sure it's allowed
18 SET GLOBAL event_scheduler=ON;
19 SHOW VARIABLES LIKE 'event_scheduler';
20 --error ER_WRONG_VALUE_FOR_VAR
21 SET GLOBAL event_scheduler=DISABLED;
22 SHOW VARIABLES LIKE 'event_scheduler';
23 --error ER_WRONG_VALUE_FOR_VAR
24 SET GLOBAL event_scheduler=-1;
25 SHOW VARIABLES LIKE 'event_scheduler';
26 --error ER_WRONG_VALUE_FOR_VAR
27 SET GLOBAL event_scheduler=2;
28 SHOW VARIABLES LIKE 'event_scheduler';
29 --error ER_WRONG_VALUE_FOR_VAR
30 SET GLOBAL event_scheduler=5;
31 SHOW VARIABLES LIKE 'event_scheduler';
33 CREATE TABLE table_1(a int);
34 CREATE TABLE table_2(a int);
35 CREATE TABLE table_3(a int);
36 CREATE TABLE table_4(a int);
38 SET GLOBAL event_scheduler=ON;
39 # We need to have 2 to make it safe with valgrind. This is probably because
40 # of when we calculate the timestamp value
41 CREATE EVENT event_1 ON SCHEDULE EVERY 2 SECOND
43   INSERT INTO table_1 VALUES (1);
45 CREATE EVENT event_2 ON SCHEDULE EVERY 1 SECOND
46 ENDS NOW() + INTERVAL 6 SECOND
47 ON COMPLETION PRESERVE
49   INSERT INTO table_2 VALUES (1);
51 CREATE EVENT event_3 ON SCHEDULE EVERY 2 SECOND ENDS NOW() + INTERVAL 1 SECOND
52 ON COMPLETION NOT PRESERVE
54   INSERT INTO table_3 VALUES (1);
56 CREATE EVENT event_4 ON SCHEDULE EVERY 1 SECOND ENDS NOW() + INTERVAL 1 SECOND
57 ON COMPLETION PRESERVE
59   INSERT INTO table_4 VALUES (1);
61 # Let event_1 insert at least 4 records into the table
62 let $wait_condition=select count(*) >= 4 from table_1;
63 --source include/wait_condition.inc
64 # Minimum of passed time is 6 seconds assuming
65 # - event executions starts immediate after creation
66 # - 4 times event_1 means an insert at ect, ect+2, ect+4, ect+6
67 # ect = event creation time
69 # Let event_2 reach the end of its execution interval
70 let $wait_condition=select count(*) = 0 from information_schema.events
71 where event_name='event_2' and status='enabled';
72 --source include/wait_condition.inc
73 # Minimum of passed time is 6 seconds.
74 # See wait_condition for event_1 above and ENDS condition for event_2.
76 # Let event_3, which is ON COMPLETION NOT PRESERVE execute and drop itself
77 let $wait_condition=select count(*) = 0 from information_schema.events
78 where event_name='event_3';
79 --source include/wait_condition.inc
81 # Let event_4 reach the end of its execution interval
82 let $wait_condition=select count(*) = 0 from information_schema.events
83 where event_name='event_4' and status='enabled';
84 --source include/wait_condition.inc
87 # On a busy system the scheduler may skip execution of events,
88 # we can't reliably expect that the data in a table to be modified
89 # by an event will be exact. Thus we do not SELECT from the tables
90 # in this test. See also
91 #    Bug#39854 events_scheduling fails sporadically on pushbuild
94 SELECT IF(TIME_TO_SEC(TIMEDIFF(ENDS,STARTS))=6, 'OK', 'ERROR')
95 FROM INFORMATION_SCHEMA.EVENTS
96 WHERE EVENT_SCHEMA=DATABASE() AND EVENT_NAME='event_2';
98 --echo "Already dropped because ended. Therefore an error."
99 --error ER_EVENT_DOES_NOT_EXIST
100 DROP EVENT event_3;
102 DROP EVENT event_1;
103 --echo "Should be preserved"
104 SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_NAME;
105 DROP EVENT event_2;
106 DROP EVENT event_4;
107 DROP TABLE table_1;
108 DROP TABLE table_2;
109 DROP TABLE table_3;
110 DROP TABLE table_4;
112 -- echo
113 -- echo Bug #50087 Interval arithmetic for Event_queue_element is not portable.
114 -- echo
116 CREATE TABLE t1(a int);
118 CREATE EVENT e1 ON SCHEDULE EVERY 1 MONTH
119 STARTS NOW() - INTERVAL 1 MONTH
120 ENDS NOW() + INTERVAL 2 MONTH
121 ON COMPLETION PRESERVE
123   INSERT INTO t1 VALUES (1);
125 CREATE EVENT e2 ON SCHEDULE EVERY 1 MONTH
126 STARTS NOW()
127 ENDS NOW() + INTERVAL 11 MONTH
128 ON COMPLETION PRESERVE
130   INSERT INTO t1 VALUES (1);
132 DROP TABLE t1;
133 DROP EVENT e1;
134 DROP EVENT e2;
137 DROP DATABASE events_test;
138 SET GLOBAL event_scheduler=@event_scheduler;
141 # End of tests
144 let $wait_condition=
145   select count(*) = 0 from information_schema.processlist
146   where db='events_test' and command = 'Connect' and user=current_user();
147 --source include/wait_condition.inc