mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Add regression tests for SELECT FOR UPDATE/SHARE NOWAIT.
Thomas Munro
This commit is contained in:
37
src/test/isolation/specs/nowait-2.spec
Normal file
37
src/test/isolation/specs/nowait-2.spec
Normal file
@@ -0,0 +1,37 @@
|
||||
# Test NOWAIT with multixact locks.
|
||||
|
||||
setup
|
||||
{
|
||||
CREATE TABLE foo (
|
||||
id int PRIMARY KEY,
|
||||
data text NOT NULL
|
||||
);
|
||||
INSERT INTO foo VALUES (1, 'x');
|
||||
}
|
||||
|
||||
teardown
|
||||
{
|
||||
DROP TABLE foo;
|
||||
}
|
||||
|
||||
session "s1"
|
||||
setup { BEGIN; }
|
||||
step "s1a" { SELECT * FROM foo FOR SHARE NOWAIT; }
|
||||
step "s1b" { COMMIT; }
|
||||
|
||||
session "s2"
|
||||
setup { BEGIN; }
|
||||
step "s2a" { SELECT * FROM foo FOR SHARE NOWAIT; }
|
||||
step "s2b" { SELECT * FROM foo FOR UPDATE NOWAIT; }
|
||||
step "s2c" { COMMIT; }
|
||||
|
||||
# s1 and s2 both get SHARE lock, creating a multixact lock, then s2
|
||||
# tries to upgrade to UPDATE but aborts because it cannot acquire a
|
||||
# multi-xact lock
|
||||
permutation "s1a" "s2a" "s2b" "s1b" "s2c"
|
||||
# the same but with the SHARE locks acquired in a different order, so
|
||||
# s2 again aborts because it can't acquired a multi-xact lock
|
||||
permutation "s2a" "s1a" "s2b" "s1b" "s2c"
|
||||
# s2 acquires SHARE then UPDATE, then s1 tries to acquire SHARE but
|
||||
# can't so aborts because it can't acquire a regular lock
|
||||
permutation "s2a" "s2b" "s1a" "s1b" "s2c"
|
33
src/test/isolation/specs/nowait-3.spec
Normal file
33
src/test/isolation/specs/nowait-3.spec
Normal file
@@ -0,0 +1,33 @@
|
||||
# Test NOWAIT with tuple locks.
|
||||
|
||||
setup
|
||||
{
|
||||
CREATE TABLE foo (
|
||||
id int PRIMARY KEY,
|
||||
data text NOT NULL
|
||||
);
|
||||
INSERT INTO foo VALUES (1, 'x');
|
||||
}
|
||||
|
||||
teardown
|
||||
{
|
||||
DROP TABLE foo;
|
||||
}
|
||||
|
||||
session "s1"
|
||||
setup { BEGIN; }
|
||||
step "s1a" { SELECT * FROM foo FOR UPDATE; }
|
||||
step "s1b" { COMMIT; }
|
||||
|
||||
session "s2"
|
||||
setup { BEGIN; }
|
||||
step "s2a" { SELECT * FROM foo FOR UPDATE; }
|
||||
step "s2b" { COMMIT; }
|
||||
|
||||
session "s3"
|
||||
setup { BEGIN; }
|
||||
step "s3a" { SELECT * FROM foo FOR UPDATE NOWAIT; }
|
||||
step "s3b" { COMMIT; }
|
||||
|
||||
# s3 skips to second record due to tuple lock held by s2
|
||||
permutation "s1a" "s2a" "s3a" "s1b" "s2b" "s3b"
|
25
src/test/isolation/specs/nowait.spec
Normal file
25
src/test/isolation/specs/nowait.spec
Normal file
@@ -0,0 +1,25 @@
|
||||
# Test NOWAIT when regular row locks can't be acquired.
|
||||
|
||||
setup
|
||||
{
|
||||
CREATE TABLE foo (
|
||||
id int PRIMARY KEY,
|
||||
data text NOT NULL
|
||||
);
|
||||
INSERT INTO foo VALUES (1, 'x');
|
||||
}
|
||||
|
||||
teardown
|
||||
{
|
||||
DROP TABLE foo;
|
||||
}
|
||||
|
||||
session "s1"
|
||||
setup { BEGIN; }
|
||||
step "s1a" { SELECT * FROM foo FOR UPDATE NOWAIT; }
|
||||
step "s1b" { COMMIT; }
|
||||
|
||||
session "s2"
|
||||
setup { BEGIN; }
|
||||
step "s2a" { SELECT * FROM foo FOR UPDATE NOWAIT; }
|
||||
step "s2b" { COMMIT; }
|
Reference in New Issue
Block a user