Skip to content

Commit 7150402

Browse files
committed
amcheck: Harden tests against concurrent autovacuums.
The previous coding of the test was vulnerable against autovacuum triggering work on one of the tables in check_btree.sql. For the purpose of the test it's entirely sufficient to check for locks taken by the current process, so add an appropriate restriction. While touching the test, expand it to also check for locks on the underlying relations, rather than just the indexes. Reported-By: Tom Lane Discussion: https://postgr.es/m/30354.1489434301@sss.pgh.pa.us
1 parent bb4a396 commit 7150402

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

contrib/amcheck/expected/check_btree.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ SELECT bt_index_parent_check('bttest_b_idx');
7777
(1 row)
7878

7979
-- make sure we don't have any leftover locks
80-
SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
80+
SELECT * FROM pg_locks
81+
WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
82+
AND pid = pg_backend_pid();
8183
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
8284
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
8385
(0 rows)

contrib/amcheck/sql/check_btree.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ BEGIN;
4949
SELECT bt_index_check('bttest_a_idx');
5050
SELECT bt_index_parent_check('bttest_b_idx');
5151
-- make sure we don't have any leftover locks
52-
SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
52+
SELECT * FROM pg_locks
53+
WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
54+
AND pid = pg_backend_pid();
5355
COMMIT;
5456

5557
-- cleanup

0 commit comments

Comments
 (0)