From 37d4c36683fbde433910812e6ab254a26807a970 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 30 Jun 2017 18:20:54 -0700 Subject: [PATCH] Add tests for statement cancellation. --- .../expected/isolation_cancellation.out | 127 ++++++++++++++++++ src/test/regress/isolation_schedule | 2 +- .../regress/specs/isolation_cancellation.spec | 80 +++++++++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 src/test/regress/expected/isolation_cancellation.out create mode 100644 src/test/regress/specs/isolation_cancellation.spec diff --git a/src/test/regress/expected/isolation_cancellation.out b/src/test/regress/expected/isolation_cancellation.out new file mode 100644 index 000000000..fc929c568 --- /dev/null +++ b/src/test/regress/expected/isolation_cancellation.out @@ -0,0 +1,127 @@ +Parsed test spec with 2 sessions + +starting permutation: s1-timeout s1-sleep10000 s1-reset s1-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-reset: + RESET ALL; + +step s1-drop: + + DROP TABLE cancel_table; + + +starting permutation: s1-timeout s1-sleep10000 s1-reset s2-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-reset: + RESET ALL; + +step s2-drop: + + DROP TABLE cancel_table; + + +starting permutation: s1-timeout s1-begin s1-sleep10000 s1-rollback s1-reset s1-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-begin: + BEGIN; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-rollback: + ROLLBACK; + +step s1-reset: + RESET ALL; + +step s1-drop: + + DROP TABLE cancel_table; + + +starting permutation: s1-timeout s1-begin s1-sleep10000 s1-rollback s1-reset s2-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-begin: + BEGIN; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-rollback: + ROLLBACK; + +step s1-reset: + RESET ALL; + +step s2-drop: + + DROP TABLE cancel_table; + + +starting permutation: s1-timeout s1-begin s1-update1 s1-sleep10000 s1-rollback s1-reset s1-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-begin: + BEGIN; + +step s1-update1: + UPDATE cancel_table SET data = '' WHERE test_id = 1; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-rollback: + ROLLBACK; + +step s1-reset: + RESET ALL; + +step s1-drop: + + DROP TABLE cancel_table; + + +starting permutation: s1-timeout s1-begin s1-update1 s1-sleep10000 s1-rollback s1-reset s2-drop +step s1-timeout: + SET statement_timeout = '100ms'; + +step s1-begin: + BEGIN; + +step s1-update1: + UPDATE cancel_table SET data = '' WHERE test_id = 1; + +step s1-sleep10000: + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; + +ERROR: canceling statement due to statement timeout +step s1-rollback: + ROLLBACK; + +step s1-reset: + RESET ALL; + +step s2-drop: + + DROP TABLE cancel_table; + diff --git a/src/test/regress/isolation_schedule b/src/test/regress/isolation_schedule index 8f7dd91e5..488e4f79a 100644 --- a/src/test/regress/isolation_schedule +++ b/src/test/regress/isolation_schedule @@ -5,6 +5,6 @@ test: isolation_add_node_vs_reference_table_operations # that come later can be parallelized test: isolation_cluster_management -test: isolation_dml_vs_repair isolation_copy_placement_vs_copy_placement +test: isolation_dml_vs_repair isolation_copy_placement_vs_copy_placement isolation_cancellation test: isolation_concurrent_dml isolation_data_migration test: isolation_drop_shards isolation_copy_placement_vs_modification diff --git a/src/test/regress/specs/isolation_cancellation.spec b/src/test/regress/specs/isolation_cancellation.spec new file mode 100644 index 000000000..872cb5070 --- /dev/null +++ b/src/test/regress/specs/isolation_cancellation.spec @@ -0,0 +1,80 @@ +# Tests around cancelling statements. As we can't trigger cancel +# interrupts directly, we use statement_timeout instead, which largely +# behaves the same as proper cancellation. + +setup +{ + CREATE TABLE cancel_table (test_id integer NOT NULL, data text); + SELECT create_distributed_table('cancel_table', 'test_id', 'hash'); + INSERT INTO cancel_table VALUES(1); +} + +teardown +{ + DROP TABLE IF EXISTS cancel_table; +} + +session "s1" + +step "s1-begin" +{ + BEGIN; +} + +step "s1-commit" +{ + COMMIT; +} + +step "s1-rollback" +{ + ROLLBACK; +} + +step "s1-sleep10000" +{ + SELECT pg_sleep(10000) FROM cancel_table WHERE test_id = 1; +} + +step "s1-timeout" +{ + SET statement_timeout = '100ms'; +} + +step "s1-update1" +{ + UPDATE cancel_table SET data = '' WHERE test_id = 1; +} + +step "s1-reset" +{ + RESET ALL; +} + +step "s1-drop" +{ + + DROP TABLE cancel_table; +} + +session "s2" + +step "s2-drop" +{ + + DROP TABLE cancel_table; +} + +# check that statement cancel works for plain selects, drop table +# afterwards to make sure sleep on workers is cancelled (thereby not +# preventing drop via locks) +permutation "s1-timeout" "s1-sleep10000" "s1-reset" "s1-drop" +permutation "s1-timeout" "s1-sleep10000" "s1-reset" "s2-drop" + +# check that statement cancel works for selects in transaction +permutation "s1-timeout" "s1-begin" "s1-sleep10000" "s1-rollback" "s1-reset" "s1-drop" +permutation "s1-timeout" "s1-begin" "s1-sleep10000" "s1-rollback" "s1-reset" "s2-drop" + +# check that statement cancel works for selects in transaction, that previously wrote +permutation "s1-timeout" "s1-begin" "s1-update1" "s1-sleep10000" "s1-rollback" "s1-reset" "s1-drop" +permutation "s1-timeout" "s1-begin" "s1-update1" "s1-sleep10000" "s1-rollback" "s1-reset" "s2-drop"