amcheck: Harden tests against concurrent autovacuums.
authorAndres Freund <[email protected]>
Tue, 14 Mar 2017 20:07:38 +0000 (13:07 -0700)
committerAndres Freund <[email protected]>
Tue, 14 Mar 2017 20:07:38 +0000 (13:07 -0700)
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

contrib/amcheck/expected/check_btree.out
contrib/amcheck/sql/check_btree.sql

index 612ce7799dc0df382b675035664fb4edaa4e2dd2..df3741e2c924a2085b2ee172436bd4aa017bf802 100644 (file)
@@ -77,7 +77,9 @@ SELECT bt_index_parent_check('bttest_b_idx');
 (1 row)
 
 -- make sure we don't have any leftover locks
-SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
+SELECT * FROM pg_locks
+WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
+    AND pid = pg_backend_pid();
  locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath 
 ----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
 (0 rows)
index 783fb635e7dec82e1545a79a1c0fbcc3cf33fb92..fd905310271f48e1cb00c9628d624d5cdbce03de 100644 (file)
@@ -49,7 +49,9 @@ BEGIN;
 SELECT bt_index_check('bttest_a_idx');
 SELECT bt_index_parent_check('bttest_b_idx');
 -- make sure we don't have any leftover locks
-SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
+SELECT * FROM pg_locks
+WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
+    AND pid = pg_backend_pid();
 COMMIT;
 
 -- cleanup