002_new_isolation_tests_for_subxids.v2.patch
application/octet-stream
Filename: 002_new_isolation_tests_for_subxids.v2.patch
Type: application/octet-stream
Part: 1
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/test/isolation/expected/subxid-overflow.out | 17 | 0 |
| src/test/isolation/isolation_schedule | 1 | 0 |
| src/test/isolation/specs/subxid-overflow.spec | 46 | 0 |
commit cdda7d36c59e20583f69130d2d05f20f6879d12f
Author: Simon Riggs <simon.riggs@enterprisedb.com>
Date: Mon Aug 8 12:15:01 2022 +0100
New iso tests for subxid-overflow
diff --git a/src/test/isolation/expected/subxid-overflow.out b/src/test/isolation/expected/subxid-overflow.out
new file mode 100644
index 0000000000..f6c96f9a34
--- /dev/null
+++ b/src/test/isolation/expected/subxid-overflow.out
@@ -0,0 +1,17 @@
+Parsed test spec with 2 sessions
+
+starting permutation: subxid xmax s2sel s1c
+step subxid: BEGIN; SELECT gen_subxids(100);
+gen_subxids
+-----------
+
+(1 row)
+
+step xmax: BEGIN; INSERT INTO subxids VALUES (1); COMMIT;
+step s2sel: SELECT count(*) FROM subxids WHERE subx = 0;
+count
+-----
+ 0
+(1 row)
+
+step s1c: COMMIT;
diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule
index 529a4cbd4d..7e10cfe022 100644
--- a/src/test/isolation/isolation_schedule
+++ b/src/test/isolation/isolation_schedule
@@ -1,3 +1,4 @@
+test: subxid-overflow
test: read-only-anomaly
test: read-only-anomaly-2
test: read-only-anomaly-3
diff --git a/src/test/isolation/specs/subxid-overflow.spec b/src/test/isolation/specs/subxid-overflow.spec
new file mode 100644
index 0000000000..fda9f449f1
--- /dev/null
+++ b/src/test/isolation/specs/subxid-overflow.spec
@@ -0,0 +1,46 @@
+# Subtransaction overflow
+#
+# This test is designed to cover some code paths which only occur when
+# one transaction has overflowed the subtransaction cache.
+
+setup
+{
+DROP TABLE IF EXISTS subxids;
+CREATE TABLE subxids (subx integer);
+
+CREATE OR REPLACE FUNCTION gen_subxids (n integer)
+ RETURNS VOID
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF n <= 0 THEN
+ INSERT INTO subxids VALUES (0);
+ RETURN;
+ ELSE
+ PERFORM gen_subxids(n - 1);
+ RETURN;
+ END IF;
+EXCEPTION /* generates a subxid */
+ WHEN raise_exception THEN NULL;
+END;
+$$;
+}
+
+teardown
+{
+ DROP TABLE subxids;
+ DROP FUNCTION gen_subxids(integer);
+}
+
+session s1
+step subxid { BEGIN; SELECT gen_subxids(100); }
+step s1c { COMMIT; }
+
+session s2
+# move xmax forwards
+step xmax { BEGIN; INSERT INTO subxids VALUES (1); COMMIT;}
+# will see step subxid as still running
+step s2sel { SELECT count(*) FROM subxids WHERE subx = 0; }
+
+# s2sel will see subxid as still running
+permutation subxid xmax s2sel s1c