rpl_misc_functions.test 3.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#
# Test of replicating some difficult functions
#
source include/master-slave.inc;

create table t1(id int, i int, r1 int, r2 int, p varchar(100));
insert into t1 values(1, connection_id(), 0, 0, "");
# don't put rand and password in the same query, to see if they replicate
# independently
# Pure rand test
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
# change the rand suite on the master (we do this because otherwise password()
# benefits from the fact that the above rand() is well replicated : 
# it picks the same sequence element, which hides a possible bug in password() replication.
set sql_log_bin=0;
insert into t1 values(6, 0, rand(), rand(), "");
delete from t1 where id=6;
set sql_log_bin=1;
# Pure password test
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
# "altogether now"
insert into t1 values(4, connection_id(), rand()*1000, rand()*1000, password('does_this_still_work?'));
select * into outfile 'rpl_misc_functions.outfile' from t1;
sync_slave_with_master;
create table t2 like t1; 
# read the values from the master table
27 28
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval load data local infile '$MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile' into table t2;
29 30
# compare them with the replica; the SELECT below should return no row
select * from t1, t2 where (t1.id=t2.id) and not(t1.i=t2.i and t1.r1=t2.r1 and t1.r2=t2.r2 and t1.p=t2.p);
31 32 33

connection master;
drop table t1;
34 35

# End of 4.1 tests
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

#
# BUG#25543 test calling rand() multiple times on the master in
# a stored procedure.
#

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

CREATE TABLE t1 (col_a double default NULL);

DELIMITER |;

# Use a SP that calls rand() multiple times
CREATE PROCEDURE test_replication_sp1()
BEGIN
 INSERT INTO t1 VALUES (rand()), (rand());
 INSERT INTO t1 VALUES (rand());
END|

# Use a SP that calls another SP to call rand() multiple times
CREATE PROCEDURE test_replication_sp2()
BEGIN
  CALL test_replication_sp1();
  CALL test_replication_sp1();
END|

# Use a SF that calls rand() multiple times
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
BEGIN
 RETURN (rand() + rand());
END|

DELIMITER ;|

# Exercise the functions and procedures then compare the results on
# the master to those on the slave.
CALL test_replication_sp1();
CALL test_replication_sp2();
INSERT INTO t1 VALUES (test_replication_sf());
INSERT INTO t1 VALUES (test_replication_sf());
INSERT INTO t1 VALUES (test_replication_sf());

# Record the results of the query on the master
--exec $MYSQL --port=$MASTER_MYPORT test -e "SELECT * FROM test.t1" > $MYSQLTEST_VARDIR/tmp/rpl_rand_master.sql

--sync_slave_with_master

# Record the results of the query on the slave
--exec $MYSQL --port=$SLAVE_MYPORT test -e "SELECT * FROM test.t1" > $MYSQLTEST_VARDIR/tmp/rpl_rand_slave.sql

# Compare the results from the master to the slave.
--exec diff $MYSQLTEST_VARDIR/tmp/rpl_rand_master.sql $MYSQLTEST_VARDIR/tmp/rpl_rand_slave.sql

# Cleanup
92
connection master;
93 94 95 96 97 98
--disable_warnings
DROP PROCEDURE IF EXISTS test_replication_sp1;
DROP PROCEDURE IF EXISTS test_replication_sp2;
DROP FUNCTION IF EXISTS test_replication_sf;
DROP TABLE IF EXISTS t1;
--enable_warnings
99
--sync_slave_with_master
100 101 102 103

# If all is good, when can cleanup our dump files.
--system rm $MYSQLTEST_VARDIR/tmp/rpl_rand_master.sql
--system rm $MYSQLTEST_VARDIR/tmp/rpl_rand_slave.sql