summaryrefslogtreecommitdiffstats
path: root/src/test/isolation/specs/truncate-conflict.spec
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/test/isolation/specs/truncate-conflict.spec
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/isolation/specs/truncate-conflict.spec')
-rw-r--r--src/test/isolation/specs/truncate-conflict.spec38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/isolation/specs/truncate-conflict.spec b/src/test/isolation/specs/truncate-conflict.spec
new file mode 100644
index 0000000..0f77ff0
--- /dev/null
+++ b/src/test/isolation/specs/truncate-conflict.spec
@@ -0,0 +1,38 @@
+# Tests for locking conflicts with TRUNCATE commands.
+
+setup
+{
+ CREATE ROLE regress_truncate_conflict;
+ CREATE TABLE truncate_tab (a int);
+}
+
+teardown
+{
+ DROP TABLE truncate_tab;
+ DROP ROLE regress_truncate_conflict;
+}
+
+session s1
+step s1_begin { BEGIN; }
+step s1_tab_lookup { SELECT count(*) >= 0 FROM truncate_tab; }
+step s1_commit { COMMIT; }
+
+session s2
+step s2_grant { GRANT TRUNCATE ON truncate_tab TO regress_truncate_conflict; }
+step s2_auth { SET ROLE regress_truncate_conflict; }
+step s2_truncate { TRUNCATE truncate_tab; }
+step s2_reset { RESET ROLE; }
+
+# The role doesn't have privileges to truncate the table, so TRUNCATE should
+# immediately fail without waiting for a lock.
+permutation s1_begin s1_tab_lookup s2_auth s2_truncate s1_commit s2_reset
+permutation s1_begin s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset
+permutation s1_begin s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset
+permutation s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset
+
+# The role has privileges to truncate the table, TRUNCATE will block if
+# another session holds a lock on the table and succeed in all cases.
+permutation s1_begin s1_tab_lookup s2_grant s2_auth s2_truncate s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s2_truncate s1_tab_lookup s1_commit s2_reset
+permutation s1_begin s2_grant s2_auth s1_tab_lookup s2_truncate s1_commit s2_reset
+permutation s2_grant s2_auth s2_truncate s1_begin s1_tab_lookup s1_commit s2_reset