Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e3b4d9

Browse files
committed
Eschew "RESET statement_timeout" in tests.
Instead, use transaction abort. Given an unlucky bout of latency, thetimeout would cancel the RESET itself. Buildfarm members gharial,lapwing, mereswine, shearwater, and sungazer witness that. Back-patchto 9.1 (all supported versions). The query_canceled test still couldtimeout before entering its subtransaction; for whatever reason, thathas yet to happen on the buildfarm.
1 parent9f1e642 commit8e3b4d9

File tree

5 files changed

+65
-33
lines changed

5 files changed

+65
-33
lines changed

‎src/test/regress/expected/plpgsql.out

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,36 +2020,28 @@ NOTICE: caught numeric_value_out_of_range or cardinality_violation
20202020
(1 row)
20212021

20222022
create temp table foo (f1 int);
2023-
create functionblockme() returns int as $$
2023+
create functionsubxact_rollback_semantics() returns int as $$
20242024
declare x int;
20252025
begin
20262026
x := 1;
20272027
insert into foo values(x);
20282028
begin
20292029
x := x + 1;
20302030
insert into foo values(x);
2031-
-- we assume this will take longer than 2 seconds:
2032-
select count(*) into x from tenk1 a, tenk1 b, tenk1 c;
2031+
raise exception 'inner';
20332032
exception
20342033
when others then
2035-
raise notice 'caught others?';
2036-
return -1;
2037-
when query_canceled then
2038-
raise notice 'nyeah nyeah, can''t stop me';
20392034
x := x * 10;
20402035
end;
20412036
insert into foo values(x);
20422037
return x;
20432038
end$$ language plpgsql;
2044-
set statement_timeout to 2000;
2045-
select blockme();
2046-
NOTICE: nyeah nyeah, can't stop me
2047-
blockme
2048-
---------
2049-
20
2039+
select subxact_rollback_semantics();
2040+
subxact_rollback_semantics
2041+
----------------------------
2042+
20
20502043
(1 row)
20512044

2052-
reset statement_timeout;
20532045
select * from foo;
20542046
f1
20552047
----
@@ -2058,6 +2050,29 @@ select * from foo;
20582050
(2 rows)
20592051

20602052
drop table foo;
2053+
create function trap_timeout() returns void as $$
2054+
begin
2055+
declare x int;
2056+
begin
2057+
-- we assume this will take longer than 2 seconds:
2058+
select count(*) into x from tenk1 a, tenk1 b, tenk1 c;
2059+
exception
2060+
when others then
2061+
raise notice 'caught others?';
2062+
when query_canceled then
2063+
raise notice 'nyeah nyeah, can''t stop me';
2064+
end;
2065+
-- Abort transaction to abandon the statement_timeout setting. Otherwise,
2066+
-- the next top-level statement would be vulnerable to the timeout.
2067+
raise exception 'end of function';
2068+
end$$ language plpgsql;
2069+
begin;
2070+
set statement_timeout to 2000;
2071+
select trap_timeout();
2072+
NOTICE: nyeah nyeah, can't stop me
2073+
ERROR: end of function
2074+
CONTEXT: PL/pgSQL function trap_timeout() line 15 at RAISE
2075+
rollback;
20612076
-- Test for pass-by-ref values being stored in proper context
20622077
create function test_variable_storage() returns text as $$
20632078
declare x text;

‎src/test/regress/expected/prepared_xacts.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ SELECT gid FROM pg_prepared_xacts;
194194
(2 rows)
195195

196196
-- pxtest3 should be locked because of the pending DROP
197+
begin;
197198
set statement_timeout to 2000;
198199
SELECT * FROM pxtest3;
199200
ERROR: canceling statement due to statement timeout
200-
reset statement_timeout;
201+
rollback;
201202
-- Disconnect, we will continue testing in a different backend
202203
\c -
203204
-- There should still be two prepared transactions
@@ -209,10 +210,11 @@ SELECT gid FROM pg_prepared_xacts;
209210
(2 rows)
210211

211212
-- pxtest3 should still be locked because of the pending DROP
213+
begin;
212214
set statement_timeout to 2000;
213215
SELECT * FROM pxtest3;
214216
ERROR: canceling statement due to statement timeout
215-
reset statement_timeout;
217+
rollback;
216218
-- Commit table creation
217219
COMMIT PREPARED 'regress-one';
218220
\d pxtest2

‎src/test/regress/expected/prepared_xacts_1.out

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ SELECT gid FROM pg_prepared_xacts;
198198
(0 rows)
199199

200200
-- pxtest3 should be locked because of the pending DROP
201+
begin;
201202
set statement_timeout to 2000;
202203
SELECT * FROM pxtest3;
203204
fff
204205
-----
205206
(0 rows)
206207

207-
reset statement_timeout;
208+
rollback;
208209
-- Disconnect, we will continue testing in a different backend
209210
\c -
210211
-- There should still be two prepared transactions
@@ -214,13 +215,14 @@ SELECT gid FROM pg_prepared_xacts;
214215
(0 rows)
215216

216217
-- pxtest3 should still be locked because of the pending DROP
218+
begin;
217219
set statement_timeout to 2000;
218220
SELECT * FROM pxtest3;
219221
fff
220222
-----
221223
(0 rows)
222224

223-
reset statement_timeout;
225+
rollback;
224226
-- Commit table creation
225227
COMMIT PREPARED 'regress-one';
226228
ERROR: prepared transaction with identifier "regress-one" does not exist

‎src/test/regress/sql/plpgsql.sql

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,37 +1745,48 @@ select trap_matching_test(1);
17451745

17461746
create temp table foo (f1int);
17471747

1748-
createfunctionblockme() returnsintas $$
1748+
createfunctionsubxact_rollback_semantics() returnsintas $$
17491749
declare xint;
17501750
begin
17511751
x :=1;
17521752
insert into foovalues(x);
17531753
begin
17541754
x := x+1;
17551755
insert into foovalues(x);
1756+
raise exception'inner';
1757+
exception
1758+
when others then
1759+
x := x*10;
1760+
end;
1761+
insert into foovalues(x);
1762+
return x;
1763+
end$$ language plpgsql;
1764+
1765+
select subxact_rollback_semantics();
1766+
select*from foo;
1767+
droptable foo;
1768+
1769+
createfunctiontrap_timeout() returns voidas $$
1770+
begin
1771+
declare xint;
1772+
begin
17561773
-- we assume this will take longer than 2 seconds:
17571774
selectcount(*) into xfrom tenk1 a, tenk1 b, tenk1 c;
17581775
exception
17591776
when others then
17601777
raise notice'caught others?';
1761-
return-1;
17621778
when query_canceled then
17631779
raise notice'nyeah nyeah, can''t stop me';
1764-
x := x*10;
17651780
end;
1766-
insert into foovalues(x);
1767-
return x;
1781+
-- Abort transaction to abandon the statement_timeout setting. Otherwise,
1782+
-- the next top-level statement would be vulnerable to the timeout.
1783+
raise exception'end of function';
17681784
end$$ language plpgsql;
17691785

1786+
begin;
17701787
set statement_timeout to2000;
1771-
1772-
select blockme();
1773-
1774-
reset statement_timeout;
1775-
1776-
select*from foo;
1777-
1778-
droptable foo;
1788+
select trap_timeout();
1789+
rollback;
17791790

17801791
-- Test for pass-by-ref values being stored in proper context
17811792
createfunctiontest_variable_storage() returnstextas $$

‎src/test/regress/sql/prepared_xacts.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ SELECT * FROM pxtest2;
122122
SELECT gidFROM pg_prepared_xacts;
123123

124124
-- pxtest3 should be locked because of the pending DROP
125+
begin;
125126
set statement_timeout to2000;
126127
SELECT*FROM pxtest3;
127-
reset statement_timeout;
128+
rollback;
128129

129130
-- Disconnect, we will continue testing in a different backend
130131
\c-
@@ -133,9 +134,10 @@ reset statement_timeout;
133134
SELECT gidFROM pg_prepared_xacts;
134135

135136
-- pxtest3 should still be locked because of the pending DROP
137+
begin;
136138
set statement_timeout to2000;
137139
SELECT*FROM pxtest3;
138-
reset statement_timeout;
140+
rollback;
139141

140142
-- Commit table creation
141143
COMMIT PREPARED'regress-one';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp