From f6d6779a06e0f764a9a12ac897c112608a4f34d1 Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Tue, 24 May 2022 19:02:06 +0400 Subject: [PATCH 1/8] Integrate isolation tests for more granular testing Many buggy cases require for their reproducing non-trivial scenarios with multiple sessions. The isolation test utility is a good choice to emulate these scenarios. Additionally isolation tests, in general, allow to perform more granular verification required to extension. Current patch adds two isolation test cases: one is for base case with queryId, another as bug fix verification for not working case of calculation queryId for relation lock waiting. Also Makefile and README were changed to account the possibility to run isolation tests. --- Makefile | 2 +- README.md | 39 +++++++++++++++--- expected/bfv_queryid_for_relation_lock.out | 42 +++++++++++++++++++ expected/queries.out | 33 ++------------- expected/queryid.out | 37 +++++++++++++++++ specs/bfv_queryid_for_relation_lock.spec | 42 +++++++++++++++++++ specs/queryid.spec | 47 ++++++++++++++++++++++ sql/queries.sql | 14 +------ 8 files changed, 207 insertions(+), 49 deletions(-) create mode 100644 expected/bfv_queryid_for_relation_lock.out create mode 100644 expected/queryid.out create mode 100644 specs/bfv_queryid_for_relation_lock.spec create mode 100644 specs/queryid.spec diff --git a/Makefile b/Makefile index ab90e59..ed18942 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ DATA_built = pg_wait_sampling--$(EXTVERSION).sql DATA = pg_wait_sampling--1.0--1.1.sql REGRESS = load queries +ISOLATION = queryid bfv_queryid_for_relation_lock -EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add EXTRA_CLEAN = pg_wait_sampling--$(EXTVERSION).sql ifdef USE_PGXS diff --git a/README.md b/README.md index aa539d8..7ce6e9f 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,43 @@ higher. Before build and install you should ensure following: Typical installation procedure may look like this: - $ git clone https://github.com/postgrespro/pg_wait_sampling.git - $ cd pg_wait_sampling - $ make USE_PGXS=1 - $ sudo make USE_PGXS=1 install - $ make USE_PGXS=1 installcheck - $ psql DB -c "CREATE EXTENSION pg_wait_sampling;" +```bash +git clone https://github.com/postgrespro/pg_wait_sampling.git +cd pg_wait_sampling +make USE_PGXS=1 install + +# Add `pg_wait_sampling` string to `shared_preload_libraries` parameter in +# `postgresql.conf` and restart PostgreSQL instance +psql DB -c "CREATE EXTENSION pg_wait_sampling;" +``` Compilation on Windows is not supported, since the extension uses symbols from PostgreSQL that are not exported. +Running full test suite on already running instance: + +```bash +make USE_PGXS=1 installcheck +``` + +> **_NOTE:_** isolation tests require `pg_stat_statements` extension as prerequisite + +To run specific test cases use the following commands: + +* for regression tests: + + ```bash + /path/to/pgsrc/or/pgxs/src/test/regress/pg_regress --bindir=/path/to/pg/bin [OTHER_OPTS] TEST1 TEST2 ... + ``` + +* for isolation tests: + + ```bash + /path/to/pgsrc/or/pgxs/src/test/isolation/pg_isolation_regress --bindir=/path/to/pg/bin [OTHER_OPTS] TEST1 TEST2 ... + ``` + +Some isolation tests have _bfv\_ (denoting "bugfix verification") prefix. They cover previously fixed buggy cases occurred in development of extension. + Usage ----- diff --git a/expected/bfv_queryid_for_relation_lock.out b/expected/bfv_queryid_for_relation_lock.out new file mode 100644 index 0000000..80bc97a --- /dev/null +++ b/expected/bfv_queryid_for_relation_lock.out @@ -0,0 +1,42 @@ +Parsed test spec with 2 sessions + +starting permutation: s1_acquire_lock_on_relation s2_wait_on_relation_lock s1_wait_one_sec s1_release_relation_lock s2_expose_wait_on_lock_in_profile +pg_wait_sampling_reset_profile +------------------------------ + +(1 row) + +step s1_acquire_lock_on_relation: + BEGIN; + LOCK pg_class IN ACCESS EXCLUSIVE MODE; + +step s2_wait_on_relation_lock: + BEGIN; + LOCK pg_class IN ACCESS SHARE MODE; + ROLLBACK; + +step s1_wait_one_sec: + SELECT pg_sleep(1); + +pg_sleep +-------- + +(1 row) + +step s1_release_relation_lock: + ROLLBACK; + +step s2_wait_on_relation_lock: <... completed> +step s2_expose_wait_on_lock_in_profile: + SELECT query + FROM pg_wait_sampling_profile pgws + LEFT JOIN pg_stat_statements pgss using (queryid) + WHERE pid = pg_backend_pid() + AND event_type = 'Lock' AND event = 'relation' + AND count between 90 and 110; + +query +----- + +(1 row) + diff --git a/expected/queries.out b/expected/queries.out index 722df5f..5a20d03 100644 --- a/expected/queries.out +++ b/expected/queries.out @@ -1,48 +1,21 @@ CREATE EXTENSION pg_wait_sampling; -WITH t as (SELECT sum(0) FROM pg_wait_sampling_current) - SELECT sum(0) FROM generate_series(1, 2), t; - sum ------ - 0 -(1 row) - -WITH t as (SELECT sum(0) FROM pg_wait_sampling_history) - SELECT sum(0) FROM generate_series(1, 2), t; - sum ------ - 0 -(1 row) - -WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile) - SELECT sum(0) FROM generate_series(1, 2), t; - sum ------ - 0 -(1 row) - --- Some dummy checks just to be sure that all our functions work and return something. +-- Some dummy checks just to be sure that all our functions work and return something SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current(pg_backend_pid()); test ------ t (1 row) -SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile(); +SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history(); test ------ t (1 row) -SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history(); +SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile(); test ------ t (1 row) -SELECT pg_wait_sampling_reset_profile(); - pg_wait_sampling_reset_profile --------------------------------- - -(1 row) - DROP EXTENSION pg_wait_sampling; diff --git a/expected/queryid.out b/expected/queryid.out new file mode 100644 index 0000000..3906b38 --- /dev/null +++ b/expected/queryid.out @@ -0,0 +1,37 @@ +Parsed test spec with 2 sessions + +starting permutation: s1_update_tuple s2_try_to_concurrently_update_tuple s1_wait_one_sec s1_rollback_txn s2_expose_wait_on_txn_in_profile +step s1_update_tuple: + BEGIN; + UPDATE test SET i = i+1; + +step s2_try_to_concurrently_update_tuple: + BEGIN; + UPDATE test SET i = i+1; + ROLLBACK; + +step s1_wait_one_sec: + SELECT pg_sleep(1); + +pg_sleep +-------- + +(1 row) + +step s1_rollback_txn: + ROLLBACK; + +step s2_try_to_concurrently_update_tuple: <... completed> +step s2_expose_wait_on_txn_in_profile: + SELECT query + FROM pg_wait_sampling_profile pgws + JOIN pg_stat_statements pgss using (queryid) + WHERE pid = pg_backend_pid() + AND event_type = 'Lock' AND event = 'transactionid' + AND count between 90 and 110; + +query +------------------------ +UPDATE test SET i = i+$1 +(1 row) + diff --git a/specs/bfv_queryid_for_relation_lock.spec b/specs/bfv_queryid_for_relation_lock.spec new file mode 100644 index 0000000..c1e00d9 --- /dev/null +++ b/specs/bfv_queryid_for_relation_lock.spec @@ -0,0 +1,42 @@ +setup { + CREATE EXTENSION pg_wait_sampling; + CREATE EXTENSION pg_stat_statements; + SELECT pg_stat_statements_reset(); + SELECT pg_wait_sampling_reset_profile(); +} + +teardown { + DROP EXTENSION pg_stat_statements; + DROP EXTENSION pg_wait_sampling; +} + +session "s1" + step "s1_acquire_lock_on_relation" { + BEGIN; + LOCK pg_class IN ACCESS EXCLUSIVE MODE; + } + step "s1_wait_one_sec" { + SELECT pg_sleep(1); + } + step "s1_release_relation_lock" { + ROLLBACK; + } + +session "s2" + step "s2_wait_on_relation_lock" { + BEGIN; + LOCK pg_class IN ACCESS SHARE MODE; + ROLLBACK; + } + # FIXME: the profile have to expose not NULL query for wait on relation lock + # After fix replace LEFT JOIN to INNER one + step "s2_expose_wait_on_lock_in_profile" { + SELECT query + FROM pg_wait_sampling_profile pgws + LEFT JOIN pg_stat_statements pgss using (queryid) + WHERE pid = pg_backend_pid() + AND event_type = 'Lock' AND event = 'relation' + AND count between 90 and 110; + } + +permutation "s1_acquire_lock_on_relation" "s2_wait_on_relation_lock" "s1_wait_one_sec" "s1_release_relation_lock" "s2_expose_wait_on_lock_in_profile" diff --git a/specs/queryid.spec b/specs/queryid.spec new file mode 100644 index 0000000..5cccdb8 --- /dev/null +++ b/specs/queryid.spec @@ -0,0 +1,47 @@ +setup { + CREATE EXTENSION pg_wait_sampling; + CREATE EXTENSION pg_stat_statements; + SELECT pg_stat_statements_reset(); + SELECT pg_wait_sampling_reset_profile(); + + CREATE TABLE test(i int); + INSERT INTO test VALUES (1); +} + +teardown { + DROP TABLE test; + DROP EXTENSION pg_stat_statements; + DROP EXTENSION pg_wait_sampling; +} + +session "s1" + step "s1_update_tuple" { + BEGIN; + UPDATE test SET i = i+1; + } + step "s1_wait_one_sec" { + SELECT pg_sleep(1); + } + step "s1_rollback_txn" { + ROLLBACK; + } + +session "s2" + step "s2_try_to_concurrently_update_tuple" { + BEGIN; + UPDATE test SET i = i+1; + ROLLBACK; + } + + # For GUC profile_period = 10ms we expect 100 samples in Lock event type + # with some little deviation, e.g., 10 samples + step "s2_expose_wait_on_txn_in_profile" { + SELECT query + FROM pg_wait_sampling_profile pgws + JOIN pg_stat_statements pgss using (queryid) + WHERE pid = pg_backend_pid() + AND event_type = 'Lock' AND event = 'transactionid' + AND count between 90 and 110; + } + +permutation "s1_update_tuple" "s2_try_to_concurrently_update_tuple" "s1_wait_one_sec" "s1_rollback_txn" "s2_expose_wait_on_txn_in_profile" diff --git a/sql/queries.sql b/sql/queries.sql index de44c6d..7146b7e 100644 --- a/sql/queries.sql +++ b/sql/queries.sql @@ -1,18 +1,8 @@ CREATE EXTENSION pg_wait_sampling; -WITH t as (SELECT sum(0) FROM pg_wait_sampling_current) - SELECT sum(0) FROM generate_series(1, 2), t; - -WITH t as (SELECT sum(0) FROM pg_wait_sampling_history) - SELECT sum(0) FROM generate_series(1, 2), t; - -WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile) - SELECT sum(0) FROM generate_series(1, 2), t; - --- Some dummy checks just to be sure that all our functions work and return something. +-- Some dummy checks just to be sure that all our functions work and return something SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current(pg_backend_pid()); -SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile(); SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history(); -SELECT pg_wait_sampling_reset_profile(); +SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile(); DROP EXTENSION pg_wait_sampling; From abbfcba819b1aa60508c9689b75cbc8b7d9565bf Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Thu, 26 May 2022 00:31:24 +0400 Subject: [PATCH 2/8] Remove useless conf.add --- conf.add | 1 - 1 file changed, 1 deletion(-) delete mode 100644 conf.add diff --git a/conf.add b/conf.add deleted file mode 100644 index 54c013d..0000000 --- a/conf.add +++ /dev/null @@ -1 +0,0 @@ -shared_preload_libraries = 'pg_wait_sampling' From 0dd954a4020d7b355854ec319df49acb86a10072 Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Thu, 26 May 2022 00:38:51 +0400 Subject: [PATCH 3/8] Add pg_stat_statements to shared_preload_libraries in run_test.sh --- run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index 3bdeb32..a009df9 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -49,7 +49,7 @@ status=$? if [ $status -ne 0 ]; then exit $status; fi # add pg_wait_sampling to shared_preload_libraries and restart cluster 'test' -echo "shared_preload_libraries = 'pg_wait_sampling'" >> $PGDATA/postgresql.conf +echo "shared_preload_libraries = 'pg_stat_statements,pg_wait_sampling'" >> $PGDATA/postgresql.conf echo "port = 55435" >> $PGDATA/postgresql.conf pg_ctl start -l /tmp/postgres.log -w From b698f0dcd6938c6b6b422b0bd1e0ef293ae0b75d Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Thu, 11 Aug 2022 19:29:19 +0400 Subject: [PATCH 4/8] Request pg_wait_sampling_profile in loop in isolation tests --- expected/bfv_queryid_for_relation_lock.out | 45 ++++-------- expected/queryid.out | 42 +++++------ specs/bfv_queryid_for_relation_lock.spec | 76 +++++++++++++------- specs/queryid.spec | 84 ++++++++++++++-------- 4 files changed, 136 insertions(+), 111 deletions(-) diff --git a/expected/bfv_queryid_for_relation_lock.out b/expected/bfv_queryid_for_relation_lock.out index 80bc97a..e53c673 100644 --- a/expected/bfv_queryid_for_relation_lock.out +++ b/expected/bfv_queryid_for_relation_lock.out @@ -1,42 +1,27 @@ Parsed test spec with 2 sessions -starting permutation: s1_acquire_lock_on_relation s2_wait_on_relation_lock s1_wait_one_sec s1_release_relation_lock s2_expose_wait_on_lock_in_profile -pg_wait_sampling_reset_profile ------------------------------- - -(1 row) - +starting permutation: s1_acquire_lock_on_relation s2_wait_on_relation_lock s1_expose_query_from_profile s1_release_relation_lock step s1_acquire_lock_on_relation: - BEGIN; - LOCK pg_class IN ACCESS EXCLUSIVE MODE; + begin; + lock pg_class in access exclusive mode; step s2_wait_on_relation_lock: - BEGIN; - LOCK pg_class IN ACCESS SHARE MODE; - ROLLBACK; + begin; + lock pg_class in access share mode; + rollback; -step s1_wait_one_sec: - SELECT pg_sleep(1); +step s1_expose_query_from_profile: + select waiting_on_relation_lock_query(pid) + from pg_stat_activity + where backend_type = 'client backend' + and wait_event_type = 'Lock'; -pg_sleep --------- - +waiting_on_relation_lock_query +------------------------------ + (1 row) step s1_release_relation_lock: - ROLLBACK; + rollback; step s2_wait_on_relation_lock: <... completed> -step s2_expose_wait_on_lock_in_profile: - SELECT query - FROM pg_wait_sampling_profile pgws - LEFT JOIN pg_stat_statements pgss using (queryid) - WHERE pid = pg_backend_pid() - AND event_type = 'Lock' AND event = 'relation' - AND count between 90 and 110; - -query ------ - -(1 row) - diff --git a/expected/queryid.out b/expected/queryid.out index 3906b38..1ef770e 100644 --- a/expected/queryid.out +++ b/expected/queryid.out @@ -1,37 +1,27 @@ Parsed test spec with 2 sessions -starting permutation: s1_update_tuple s2_try_to_concurrently_update_tuple s1_wait_one_sec s1_rollback_txn s2_expose_wait_on_txn_in_profile -step s1_update_tuple: - BEGIN; - UPDATE test SET i = i+1; +starting permutation: s1_update_tuple_in_txn s2_try_to_concurrently_update_tuple s1_expose_query_from_profile s1_rollback_txn +step s1_update_tuple_in_txn: + begin; + update test set i = i+1; step s2_try_to_concurrently_update_tuple: - BEGIN; - UPDATE test SET i = i+1; - ROLLBACK; + begin; + update test set i = i+1; + rollback; -step s1_wait_one_sec: - SELECT pg_sleep(1); +step s1_expose_query_from_profile: + select waiting_on_txnid_lock_query(pid) + from pg_stat_activity + where backend_type = 'client backend' + and wait_event_type = 'Lock'; -pg_sleep --------- - +waiting_on_txnid_lock_query +--------------------------- +update test set i = i+$1 (1 row) step s1_rollback_txn: - ROLLBACK; + rollback; step s2_try_to_concurrently_update_tuple: <... completed> -step s2_expose_wait_on_txn_in_profile: - SELECT query - FROM pg_wait_sampling_profile pgws - JOIN pg_stat_statements pgss using (queryid) - WHERE pid = pg_backend_pid() - AND event_type = 'Lock' AND event = 'transactionid' - AND count between 90 and 110; - -query ------------------------- -UPDATE test SET i = i+$1 -(1 row) - diff --git a/specs/bfv_queryid_for_relation_lock.spec b/specs/bfv_queryid_for_relation_lock.spec index c1e00d9..9588694 100644 --- a/specs/bfv_queryid_for_relation_lock.spec +++ b/specs/bfv_queryid_for_relation_lock.spec @@ -1,42 +1,68 @@ setup { - CREATE EXTENSION pg_wait_sampling; - CREATE EXTENSION pg_stat_statements; - SELECT pg_stat_statements_reset(); - SELECT pg_wait_sampling_reset_profile(); + create extension pg_wait_sampling; + create extension pg_stat_statements; + select pg_stat_statements_reset(); + select pg_wait_sampling_reset_profile(); + + create function waiting_on_relation_lock_query(_pid int) returns text + language plpgsql + as $function$ + declare + i int = 0; + wait_count int; + query_text text; + IDLE_INTERVAL constant int = 1; + DEADLINE constant int = 10; + begin + loop + i = i + 1; + + select count, query + into wait_count, query_text + from pg_wait_sampling_profile pgws + left join pg_stat_statements pgss using (queryid) + where pid = _pid + and event_type = 'Lock' AND event = 'relation'; + + exit when wait_count > 0; + if i > DEADLINE / IDLE_INTERVAL then + raise 'timed out'; + end if; + + perform pg_sleep(IDLE_INTERVAL); + end loop; + return query_text; + end; + $function$; } teardown { - DROP EXTENSION pg_stat_statements; - DROP EXTENSION pg_wait_sampling; + drop function waiting_on_relation_lock_query(int); + drop extension pg_stat_statements; + drop extension pg_wait_sampling; } session "s1" step "s1_acquire_lock_on_relation" { - BEGIN; - LOCK pg_class IN ACCESS EXCLUSIVE MODE; + begin; + lock pg_class in access exclusive mode; } - step "s1_wait_one_sec" { - SELECT pg_sleep(1); + # FIXME: the profile have to expose not NULL query for wait on relation lock + step "s1_expose_query_from_profile" { + select waiting_on_relation_lock_query(pid) + from pg_stat_activity + where backend_type = 'client backend' + and wait_event_type = 'Lock'; } step "s1_release_relation_lock" { - ROLLBACK; + rollback; } session "s2" step "s2_wait_on_relation_lock" { - BEGIN; - LOCK pg_class IN ACCESS SHARE MODE; - ROLLBACK; - } - # FIXME: the profile have to expose not NULL query for wait on relation lock - # After fix replace LEFT JOIN to INNER one - step "s2_expose_wait_on_lock_in_profile" { - SELECT query - FROM pg_wait_sampling_profile pgws - LEFT JOIN pg_stat_statements pgss using (queryid) - WHERE pid = pg_backend_pid() - AND event_type = 'Lock' AND event = 'relation' - AND count between 90 and 110; + begin; + lock pg_class in access share mode; + rollback; } -permutation "s1_acquire_lock_on_relation" "s2_wait_on_relation_lock" "s1_wait_one_sec" "s1_release_relation_lock" "s2_expose_wait_on_lock_in_profile" +permutation "s1_acquire_lock_on_relation" "s2_wait_on_relation_lock" "s1_expose_query_from_profile" "s1_release_relation_lock" diff --git a/specs/queryid.spec b/specs/queryid.spec index 5cccdb8..f835186 100644 --- a/specs/queryid.spec +++ b/specs/queryid.spec @@ -1,47 +1,71 @@ setup { - CREATE EXTENSION pg_wait_sampling; - CREATE EXTENSION pg_stat_statements; - SELECT pg_stat_statements_reset(); - SELECT pg_wait_sampling_reset_profile(); + create extension pg_wait_sampling; + create extension pg_stat_statements; + select pg_stat_statements_reset(); + select pg_wait_sampling_reset_profile(); - CREATE TABLE test(i int); - INSERT INTO test VALUES (1); + create function waiting_on_txnid_lock_query(_pid int) returns text + language plpgsql + as $function$ + declare + i int = 0; + wait_count int; + query_text text; + IDLE_INTERVAL constant int = 1; + DEADLINE constant int = 10; + begin + loop + i = i + 1; + + select count, query + into wait_count, query_text + from pg_wait_sampling_profile pgws + left join pg_stat_statements pgss using (queryid) + where pid = _pid + and event_type = 'Lock' AND event = 'transactionid'; + + exit when wait_count > 0; + if i > DEADLINE / IDLE_INTERVAL then + raise 'timed out'; + end if; + + perform pg_sleep(IDLE_INTERVAL); + end loop; + return query_text; + end; + $function$; + + create table test(i int); + insert into test values (1); } teardown { - DROP TABLE test; - DROP EXTENSION pg_stat_statements; - DROP EXTENSION pg_wait_sampling; + drop table test; + drop function waiting_on_txnid_lock_query(int); + drop extension pg_stat_statements; + drop extension pg_wait_sampling; } session "s1" - step "s1_update_tuple" { - BEGIN; - UPDATE test SET i = i+1; + step "s1_update_tuple_in_txn" { + begin; + update test set i = i+1; } - step "s1_wait_one_sec" { - SELECT pg_sleep(1); + step "s1_expose_query_from_profile" { + select waiting_on_txnid_lock_query(pid) + from pg_stat_activity + where backend_type = 'client backend' + and wait_event_type = 'Lock'; } step "s1_rollback_txn" { - ROLLBACK; + rollback; } session "s2" step "s2_try_to_concurrently_update_tuple" { - BEGIN; - UPDATE test SET i = i+1; - ROLLBACK; - } - - # For GUC profile_period = 10ms we expect 100 samples in Lock event type - # with some little deviation, e.g., 10 samples - step "s2_expose_wait_on_txn_in_profile" { - SELECT query - FROM pg_wait_sampling_profile pgws - JOIN pg_stat_statements pgss using (queryid) - WHERE pid = pg_backend_pid() - AND event_type = 'Lock' AND event = 'transactionid' - AND count between 90 and 110; + begin; + update test set i = i+1; + rollback; } -permutation "s1_update_tuple" "s2_try_to_concurrently_update_tuple" "s1_wait_one_sec" "s1_rollback_txn" "s2_expose_wait_on_txn_in_profile" +permutation "s1_update_tuple_in_txn" "s2_try_to_concurrently_update_tuple" "s1_expose_query_from_profile" "s1_rollback_txn" From d4afb60d7d0e35f22f45f7cfb11a148ec5df0586 Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Sun, 14 Aug 2022 20:38:25 +0400 Subject: [PATCH 5/8] Distribution of isolation test utilities for pg12 and pg13 --- Dockerfile.tmpl | 6 ++++++ run_tests.sh | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index eaf70c8..88d2247 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -21,6 +21,12 @@ RUN if [ "${CHECK_CODE}" = "false" ] ; then \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ fi +RUN if [ "${CHECK_CODE}" = "false" ] && { [ "${PG_VERSION}" = "12" ] || [ "${PG_VERSION}" = "13" ]; } ; then \ + apk --no-cache add git flex bison perl \ + --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ + --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ + fi + RUN mkdir -p ${PGDATA} && \ mkdir /pg/src && \ chown postgres:postgres ${PGDATA} && \ diff --git a/run_tests.sh b/run_tests.sh index a009df9..92301fd 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -35,6 +35,17 @@ elif [ "$CHECK_CODE" = "cppcheck" ]; then exit $status fi +# compile and setup tools for isolation tests for pg12 and pg13 +if [ "$PG_VERSION" = "12" ] || [ "$PG_VERSION" = "13" ] ; then + git clone https://github.com/postgres/postgres.git -b $(pg_config --version | awk '{print $2}' | sed -r 's/\./_/' | sed -e 's/^/REL_/') --depth=1 + cd postgres + ./configure --prefix=/usr/local --without-readline --without-zlib + cd src/test/isolation + make install + mkdir $(dirname $(pg_config --pgxs))/../../src/test/isolation + cp isolationtester pg_isolation_regress -t $(dirname $(pg_config --pgxs))/../../src/test/isolation +fi + # don't forget to "make clean" make USE_PGXS=1 clean From f4598c20ebff4077172ca1cc027dbeec1b3fafc8 Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Mon, 15 Aug 2022 10:58:58 +0400 Subject: [PATCH 6/8] Final fixes to ci scripts --- Dockerfile.tmpl | 15 +++++++-------- run_tests.sh | 7 ++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 88d2247..07aac4e 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -19,13 +19,12 @@ RUN if [ "${CHECK_CODE}" = "false" ] ; then \ apk --no-cache add curl python3 gcc make musl-dev llvm clang clang-dev \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ - fi - -RUN if [ "${CHECK_CODE}" = "false" ] && { [ "${PG_VERSION}" = "12" ] || [ "${PG_VERSION}" = "13" ]; } ; then \ - apk --no-cache add git flex bison perl \ - --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ - --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ - fi + if [ "${PG_VERSION}" = "12" ] || [ "${PG_VERSION}" = "13" ] ; then \ + apk --no-cache add git flex bison perl \ + --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ + --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ + fi; \ +fi RUN mkdir -p ${PGDATA} && \ mkdir /pg/src && \ @@ -37,4 +36,4 @@ ADD . /pg/src WORKDIR /pg/src RUN chmod -R go+rwX /pg/src USER postgres -ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} bash run_tests.sh +ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} PG_VERSION=${PG_VERSION} bash run_tests.sh diff --git a/run_tests.sh b/run_tests.sh index 92301fd..a556ee6 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -8,6 +8,7 @@ set -eux +echo PG_VERSION=$PG_VERSION echo CHECK_CODE=$CHECK_CODE status=0 @@ -37,13 +38,17 @@ fi # compile and setup tools for isolation tests for pg12 and pg13 if [ "$PG_VERSION" = "12" ] || [ "$PG_VERSION" = "13" ] ; then - git clone https://github.com/postgres/postgres.git -b $(pg_config --version | awk '{print $2}' | sed -r 's/\./_/' | sed -e 's/^/REL_/') --depth=1 + PWD_SAVED=`pwd` + git clone https://github.com/postgres/postgres.git \ + -b $(pg_config --version | awk '{print $2}' | sed -r 's/\./_/' | sed -e 's/^/REL_/') \ + --depth=1 cd postgres ./configure --prefix=/usr/local --without-readline --without-zlib cd src/test/isolation make install mkdir $(dirname $(pg_config --pgxs))/../../src/test/isolation cp isolationtester pg_isolation_regress -t $(dirname $(pg_config --pgxs))/../../src/test/isolation + cd $PWD_SAVED fi # don't forget to "make clean" From 640671905e5f19e4cd98b726ffd50addae26090e Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Thu, 8 Sep 2022 22:20:22 +0400 Subject: [PATCH 7/8] Allow running isolation tests for pg14+ in pgxs environment --- Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ed18942..10915a3 100644 --- a/Makefile +++ b/Makefile @@ -9,15 +9,22 @@ DATA_built = pg_wait_sampling--$(EXTVERSION).sql DATA = pg_wait_sampling--1.0--1.1.sql REGRESS = load queries -ISOLATION = queryid bfv_queryid_for_relation_lock +ISOLATION_TESTS = queryid bfv_queryid_for_relation_lock EXTRA_CLEAN = pg_wait_sampling--$(EXTVERSION).sql ifdef USE_PGXS PG_CONFIG = pg_config -PGXS := $(shell $(PG_CONFIG) --pgxs) +PGXS = $(shell $(PG_CONFIG) --pgxs) +NO_INSTALLCHECK = 1 include $(PGXS) +installcheck: submake $(REGRESS_PREP) + $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS) +ifeq ($(shell test $(MAJORVERSION) -ge 14; echo $$?),0) + $(pg_isolation_regress_installcheck) $(ISOLATION_OPTS) $(ISOLATION_TESTS) +endif else +ISOLATION=$(ISOLATION_TESTS) subdir = contrib/pg_wait_sampling top_builddir = ../.. include $(top_builddir)/src/Makefile.global From 7503dd645b7c98e27e3a6e3eae502ce45918d723 Mon Sep 17 00:00:00 2001 From: Maksim Milyutin Date: Thu, 8 Sep 2022 22:41:27 +0400 Subject: [PATCH 8/8] Revert changes that setup tools for isolation tests in CI pipeline for pg12 and pg13 --- Dockerfile.tmpl | 9 ++------- run_tests.sh | 16 ---------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/Dockerfile.tmpl b/Dockerfile.tmpl index 07aac4e..eaf70c8 100644 --- a/Dockerfile.tmpl +++ b/Dockerfile.tmpl @@ -19,12 +19,7 @@ RUN if [ "${CHECK_CODE}" = "false" ] ; then \ apk --no-cache add curl python3 gcc make musl-dev llvm clang clang-dev \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ - if [ "${PG_VERSION}" = "12" ] || [ "${PG_VERSION}" = "13" ] ; then \ - apk --no-cache add git flex bison perl \ - --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community \ - --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/main; \ - fi; \ -fi + fi RUN mkdir -p ${PGDATA} && \ mkdir /pg/src && \ @@ -36,4 +31,4 @@ ADD . /pg/src WORKDIR /pg/src RUN chmod -R go+rwX /pg/src USER postgres -ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} PG_VERSION=${PG_VERSION} bash run_tests.sh +ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} bash run_tests.sh diff --git a/run_tests.sh b/run_tests.sh index a556ee6..a009df9 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -8,7 +8,6 @@ set -eux -echo PG_VERSION=$PG_VERSION echo CHECK_CODE=$CHECK_CODE status=0 @@ -36,21 +35,6 @@ elif [ "$CHECK_CODE" = "cppcheck" ]; then exit $status fi -# compile and setup tools for isolation tests for pg12 and pg13 -if [ "$PG_VERSION" = "12" ] || [ "$PG_VERSION" = "13" ] ; then - PWD_SAVED=`pwd` - git clone https://github.com/postgres/postgres.git \ - -b $(pg_config --version | awk '{print $2}' | sed -r 's/\./_/' | sed -e 's/^/REL_/') \ - --depth=1 - cd postgres - ./configure --prefix=/usr/local --without-readline --without-zlib - cd src/test/isolation - make install - mkdir $(dirname $(pg_config --pgxs))/../../src/test/isolation - cp isolationtester pg_isolation_regress -t $(dirname $(pg_config --pgxs))/../../src/test/isolation - cd $PWD_SAVED -fi - # don't forget to "make clean" make USE_PGXS=1 clean