# Concurrent UPDATE test
#
# Note: 1. The "--real_sleep 1" are not needed for the test logics itself.
#          I just want to exclude that the visible strange effect is caused
#          by a currently not detected but thinkable bug around timing/when
#          changes become visible ....
#       2. The "--disable_abort_on_error" before and "--enable_abort_on_error"
#          after "reap" are used with the intention to get a reject file.
#          Both lines can be removed from an final testcase if we are sure
#          that "reap" must not get a server error.
#

--echo #---- Bug 22303 ----

--source include/have_falcon.inc
let $engine = Falcon;

# Can't test this with embedded server
--source include/not_embedded.inc

--echo # Initialization
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
eval CREATE TABLE t1 (id INTEGER, x CHAR(20)) ENGINE=$engine;
INSERT INTO t1 VALUES(0, 'Initialized');
COMMIT;

--echo # Establish connection con1 (user=root)
connect (con1,localhost,root,,);
SET AUTOCOMMIT = 0;
--echo # Establish connection con2 (user=root)
connect (con2,localhost,root,,);
SET AUTOCOMMIT = 0;

--echo # Switch to connection con1
connection con1;
UPDATE t1 SET x = 'Update by con1' WHERE id = 0;

--real_sleep 1

--echo # Switch to connection con2
connection con2;
--echo # The following UPDATE t1 SET x = 'Update by con2' WHERE id = 0 is sent without
--echo # waiting of the client (for this session) for completion.
--echo # That means if you see the statement printed in the protocoll
--echo # the outcome of the statement is unknown and no following server
--echo # message etc. does not mean that the statement was successful
--echo # completed.
--send UPDATE t1 SET x = 'Update by con2' WHERE id = 0;

--real_sleep 1

--echo # Switch to connection con1
connection con1;
ROLLBACK;

--real_sleep 1

--echo # Switch to connection con2
connection con2;
--echo # Here the connection prints the outcome of the preceeding
--echo # UPDATE t1 SET x = 'Update by con2' WHERE id = 0;
--echo # If there is nothing printed before the next statement (COMMIT)
--echo # appears the outcome was success.
# Bug#22303: crash on concurrent updates, ROLLBACK (Falcon)
--disable_abort_on_error
reap;
--enable_abort_on_error
COMMIT;
SELECT * FROM t1;
COMMIT;

DROP TABLE t1;
