summaryrefslogtreecommitdiffstats
path: root/src/test/isolation/specs/total-cash.spec
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:46:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:46:48 +0000
commit311bcfc6b3acdd6fd152798c7f287ddf74fa2a98 (patch)
tree0ec307299b1dada3701e42f4ca6eda57d708261e /src/test/isolation/specs/total-cash.spec
parentInitial commit. (diff)
downloadpostgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.tar.xz
postgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.zip
Adding upstream version 15.4.upstream/15.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/isolation/specs/total-cash.spec')
-rw-r--r--src/test/isolation/specs/total-cash.spec28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/isolation/specs/total-cash.spec b/src/test/isolation/specs/total-cash.spec
new file mode 100644
index 0000000..d98121a
--- /dev/null
+++ b/src/test/isolation/specs/total-cash.spec
@@ -0,0 +1,28 @@
+# Total Cash test
+#
+# Another famous test of snapshot isolation anomaly.
+#
+# Any overlap between the transactions must cause a serialization failure.
+
+setup
+{
+ CREATE TABLE accounts (accountid text NOT NULL PRIMARY KEY, balance numeric not null);
+ INSERT INTO accounts VALUES ('checking', 600),('savings',600);
+}
+
+teardown
+{
+ DROP TABLE accounts;
+}
+
+session s1
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wx1 { UPDATE accounts SET balance = balance - 200 WHERE accountid = 'checking'; }
+step rxy1 { SELECT SUM(balance) FROM accounts; }
+step c1 { COMMIT; }
+
+session s2
+setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
+step wy2 { UPDATE accounts SET balance = balance - 200 WHERE accountid = 'savings'; }
+step rxy2 { SELECT SUM(balance) FROM accounts; }
+step c2 { COMMIT; }