1#
2# SUMMARY
3#   Check that statement reading table '$table' doesn't allow concurrent
4#   inserts in it.
5#
6# PARAMETERS
7#   $table         Table in which concurrent inserts should be disallowed.
8#   $con_aux1      Name of the first auxiliary connection to be used by this
9#                  script.
10#   $con_aux2      Name of the second auxiliary connection to be used by this
11#                  script.
12#   $statement     Statement to be checked.
13#   $restore_table Table which might be modified by statement to be checked
14#                  and thus needs backing up before its execution and
15#                  restoring after it (can be empty).
16#
17# EXAMPLE
18#    lock_sync.test
19#
20--disable_result_log
21--disable_query_log
22
23# Reset DEBUG_SYNC facility for safety.
24set debug_sync= "RESET";
25
26if ($restore_table)
27{
28--eval create temporary table t_backup select * from $restore_table;
29}
30
31connection $con_aux1;
32set debug_sync='after_lock_tables_takes_lock SIGNAL parked WAIT_FOR go';
33--send_eval $statement;
34
35connection $con_aux2;
36set debug_sync='now WAIT_FOR parked';
37--send_eval insert into $table (i) values (0);
38
39--enable_result_log
40--enable_query_log
41connection default;
42# Wait until concurrent insert is successfully blocked because
43# of our statement.
44let $wait_condition=
45  select count(*) = 1 from information_schema.processlist
46  where state = "Waiting for table level lock" and
47        info = "insert into $table (i) values (0)";
48--source include/wait_condition.inc
49
50--disable_result_log
51--disable_query_log
52
53set debug_sync= 'now SIGNAL go';
54connection $con_aux1;
55--reap
56connection $con_aux2;
57--reap
58connection default;
59
60if ($success)
61{
62--echo Success: '$statement' doesn't allow concurrent inserts into '$table'.
63}
64if (!$success)
65{
66--echo Error: '$statement' allows concurrent inserts into '$table'!
67}
68
69--eval delete from $table where i = 0;
70
71if ($restore_table)
72{
73--eval truncate table $restore_table;
74--eval insert into $restore_table select * from t_backup;
75drop temporary table t_backup;
76}
77
78# Clean-up. Reset DEBUG_SYNC facility after use.
79set debug_sync= "RESET";
80
81--enable_result_log
82--enable_query_log
83