--source include/have_partition.inc
--source include/have_innodb.inc

SET @old_autocommit = @@global.autocommit;
SET @@global.autocommit = 0;
SET @old_lock_wait_timeout= @@global.lock_wait_timeout;
SET @@global.lock_wait_timeout = 1;
SET @old_innodb_lock_wait_timeout= @@global.innodb_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout = 1;

USE test;

CREATE USER 'mysqltest1'@'localhost';
CREATE USER 'mysqltest2'@'localhost';
GRANT ALL PRIVILEGES ON test.* TO 'mysqltest1'@'localhost';
GRANT ALL PRIVILEGES ON test.* TO 'mysqltest2'@'localhost';

CREATE TABLE t1 (a int PRIMARY KEY, b varchar(128), KEY (b))
ENGINE = InnoDB
PARTITION BY HASH (a) PARTITIONS 13;

INSERT INTO t1 VALUES (11, 'First row, p11');
INSERT INTO t1 VALUES (12, 'First row, p12');

--enable_connect_log
connect (test1,localhost,mysqltest1,,test);
connect (test2,localhost,mysqltest2,,test);

connection test1;
INSERT INTO t1 VALUES (13+11, 'Second row, p11');
INSERT INTO t1 VALUES (13+12, 'Second row, p12');
SELECT * FROM t1 ORDER BY a;

connection test2;
--error ER_LOCK_WAIT_TIMEOUT
INSERT INTO t1 VALUES (13+11, 'Second row, p11');
--error ER_LOCK_WAIT_TIMEOUT
INSERT INTO t1 VALUES (13+12, 'Second row, p12');
SELECT * FROM t1 ORDER BY a;
COMMIT;

connection test1;
SELECT * FROM t1 ORDER BY a;
COMMIT;

connection default;
DROP TABLE t1;
DROP USER 'mysqltest1'@'localhost';
DROP USER 'mysqltest2'@'localhost';
SET @@global.autocommit = @old_autocommit;
SET @@global.lock_wait_timeout= @old_lock_wait_timeout;
SET @@global.innodb_lock_wait_timeout= @old_innodb_lock_wait_timeout;
