From 53f0777e76ca78538744621487f15e25d8b43dd5 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 19 Dec 2022 16:35:09 +1100 Subject: [PATCH v1] isolationstester - example of pub-sub spec --- src/test/isolation/Makefile | 3 + src/test/isolation/expected/pub-sub.out | 249 ++++++++++++++++++++++++++++++++ src/test/isolation/specs/pub-sub.spec | 84 +++++++++++ 3 files changed, 336 insertions(+) create mode 100644 src/test/isolation/expected/pub-sub.out create mode 100644 src/test/isolation/specs/pub-sub.spec diff --git a/src/test/isolation/Makefile b/src/test/isolation/Makefile index b8738b7..fe7e8cb 100644 --- a/src/test/isolation/Makefile +++ b/src/test/isolation/Makefile @@ -78,3 +78,6 @@ installcheck-prepared-txns: all temp-install check-prepared-txns: all temp-install $(pg_isolation_regress_check) --schedule=$(srcdir)/isolation_schedule prepared-transactions prepared-transactions-cic + +check-pub-sub: temp-install + $(pg_isolation_regress_check) pub-sub diff --git a/src/test/isolation/expected/pub-sub.out b/src/test/isolation/expected/pub-sub.out new file mode 100644 index 0000000..65339f8 --- /dev/null +++ b/src/test/isolation/expected/pub-sub.out @@ -0,0 +1,249 @@ +Parsed test spec with 3 sessions +session 'ps1' specifies connection info 'host=localhost port=7651' +session 'ps2' specifies connection info 'host=localhost port=7651' +session 'sub' specifies connection info 'host=localhost port=7652' + +starting permutation: ps1_begin ps1_ins ps1_commit ps1_sel ps2_sel sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps1_commit: COMMIT; +step ps1_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +(1 row) + +step ps2_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +(1 row) + +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +(1 row) + + +starting permutation: ps2_begin ps2_ins ps2_commit ps1_sel ps2_sel sub_sleep sub_sel +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps2_commit: COMMIT; +step ps1_sel: SELECT * FROM tbl ORDER BY id; + id +--- +222 +(1 row) + +step ps2_sel: SELECT * FROM tbl ORDER BY id; + id +--- +222 +(1 row) + +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +222 +(1 row) + + +starting permutation: ps1_begin ps1_ins ps1_rollback ps1_sel sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps1_rollback: ROLLBACK; +step ps1_sel: SELECT * FROM tbl ORDER BY id; +id +-- +(0 rows) + +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; +id +-- +(0 rows) + + +starting permutation: ps1_begin ps1_ins ps2_begin ps2_ins ps1_rollback ps2_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_rollback: ROLLBACK; +step ps2_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +222 +(1 row) + + +starting permutation: ps1_begin ps1_ins ps2_begin ps2_ins ps1_commit ps2_rollback sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_commit: COMMIT; +step ps2_rollback: ROLLBACK; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +(1 row) + + +starting permutation: ps1_begin ps1_ins ps2_begin ps2_ins ps2_commit ps1_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps2_commit: COMMIT; +step ps1_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + + +starting permutation: ps1_begin ps1_ins ps2_begin ps2_ins ps1_commit ps2_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_commit: COMMIT; +step ps2_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + + +starting permutation: ps1_begin ps2_begin ps1_ins ps2_ins ps2_commit ps1_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps2_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps2_commit: COMMIT; +step ps1_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + + +starting permutation: ps1_begin ps2_begin ps1_ins ps2_ins ps1_commit ps2_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps2_begin: BEGIN; +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_commit: COMMIT; +step ps2_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + + +starting permutation: ps1_begin ps2_begin ps2_ins ps1_ins ps2_commit ps1_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps2_commit: COMMIT; +step ps1_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + + +starting permutation: ps1_begin ps2_begin ps2_ins ps1_ins ps1_commit ps2_commit sub_sleep sub_sel +step ps1_begin: BEGIN; +step ps2_begin: BEGIN; +step ps2_ins: INSERT INTO tbl VALUES (222); +step ps1_ins: INSERT INTO tbl VALUES (111); +step ps1_commit: COMMIT; +step ps2_commit: COMMIT; +step sub_sleep: SELECT pg_sleep(3); +pg_sleep +-------- + +(1 row) + +step sub_sel: SELECT * FROM tbl ORDER BY id; + id +--- +111 +222 +(2 rows) + diff --git a/src/test/isolation/specs/pub-sub.spec b/src/test/isolation/specs/pub-sub.spec new file mode 100644 index 0000000..70c7f4d --- /dev/null +++ b/src/test/isolation/specs/pub-sub.spec @@ -0,0 +1,84 @@ +# +# Test assumes there is already setup so +# +# PG server for publisher (running on port 7651) +# - has TABLE tbl +# - has PUBLICATION pub1 +# +# PG server for subscriber (running on port 7652) +# - has TABLE tbl +# - has SUBSCRIPTION sub1 subscribing to pub1 +# +# ~~~ +# +# Now the following spec tests are configured to have multiple sessions on the +# publisher so we can interleave the WAL records to see the effect for the +# subscription +# +# ~~~ +# +# How to run +# 1. Run . ./test_init.sh to create the PG instances, table, and publication/subscription +# 2. Run the isolation tester make check-pub-sub (runs this spec) +# 3. Check the logs of the PG instances +# + +################ +# Publisher node +################ +session ps1 +conninfo "host=localhost port=7651" +setup +{ + TRUNCATE TABLE tbl; +} +step ps1_ins { INSERT INTO tbl VALUES (111); } +step ps1_sel { SELECT * FROM tbl ORDER BY id; } +step ps1_begin { BEGIN; } +step ps1_commit { COMMIT; } +step ps1_rollback { ROLLBACK; } + +session ps2 +conninfo "host=localhost port=7651" +step ps2_ins { INSERT INTO tbl VALUES (222); } +step ps2_sel { SELECT * FROM tbl ORDER BY id; } +step ps2_begin { BEGIN; } +step ps2_commit { COMMIT; } +step ps2_rollback { ROLLBACK; } + +################# +# Subscriber node +################# +session sub +conninfo "host=localhost port=7652" +setup +{ + TRUNCATE TABLE tbl; +} +step sub_sleep { SELECT pg_sleep(3); } +step sub_sel { SELECT * FROM tbl ORDER BY id; } + +####### +# Tests +####### + +# single tx +permutation ps1_begin ps1_ins ps1_commit ps1_sel ps2_sel sub_sleep sub_sel +permutation ps2_begin ps2_ins ps2_commit ps1_sel ps2_sel sub_sleep sub_sel + +# rollback +permutation ps1_begin ps1_ins ps1_rollback ps1_sel sub_sleep sub_sel + +# overlapping tx rollback and commit +permutation ps1_begin ps1_ins ps2_begin ps2_ins ps1_rollback ps2_commit sub_sleep sub_sel +permutation ps1_begin ps1_ins ps2_begin ps2_ins ps1_commit ps2_rollback sub_sleep sub_sel + +# overlapping tx commits +permutation ps1_begin ps1_ins ps2_begin ps2_ins ps2_commit ps1_commit sub_sleep sub_sel +permutation ps1_begin ps1_ins ps2_begin ps2_ins ps1_commit ps2_commit sub_sleep sub_sel + +permutation ps1_begin ps2_begin ps1_ins ps2_ins ps2_commit ps1_commit sub_sleep sub_sel +permutation ps1_begin ps2_begin ps1_ins ps2_ins ps1_commit ps2_commit sub_sleep sub_sel + +permutation ps1_begin ps2_begin ps2_ins ps1_ins ps2_commit ps1_commit sub_sleep sub_sel +permutation ps1_begin ps2_begin ps2_ins ps1_ins ps1_commit ps2_commit sub_sleep sub_sel -- 1.8.3.1