summaryrefslogtreecommitdiffstats
path: root/src/test/isolation/specs/truncate-conflict.spec
diff options
context:
space:
mode:
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