Avoid updating inactive_since for invalid replication slots.
[pgsql.git] / contrib / amcheck / t / 002_cic.pl
blob0b6a5a9e4641172e6aeff80ec597af9953f0e43b
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
4 # Test CREATE INDEX CONCURRENTLY with concurrent modifications
5 use strict;
6 use warnings FATAL => 'all';
8 use PostgreSQL::Test::Cluster;
9 use PostgreSQL::Test::Utils;
11 use Test::More;
13 my $node;
16 # Test set-up
18 $node = PostgreSQL::Test::Cluster->new('CIC_test');
19 $node->init;
20 $node->append_conf('postgresql.conf',
21 'lock_timeout = ' . (1000 * $PostgreSQL::Test::Utils::timeout_default));
22 $node->start;
23 $node->safe_psql('postgres', q(CREATE EXTENSION amcheck));
24 $node->safe_psql('postgres', q(CREATE TABLE tbl(i int)));
25 $node->safe_psql('postgres', q(CREATE INDEX idx ON tbl(i)));
28 # Stress CIC with pgbench.
30 # pgbench might try to launch more than one instance of the CIC
31 # transaction concurrently. That would deadlock, so use an advisory
32 # lock to ensure only one CIC runs at a time.
34 $node->pgbench(
35 '--no-vacuum --client=5 --transactions=100',
37 [qr{actually processed}],
38 [qr{^$}],
39 'concurrent INSERTs and CIC',
41 '002_pgbench_concurrent_transaction' => q(
42 BEGIN;
43 INSERT INTO tbl VALUES(0);
44 COMMIT;
46 '002_pgbench_concurrent_transaction_savepoints' => q(
47 BEGIN;
48 SAVEPOINT s1;
49 INSERT INTO tbl VALUES(0);
50 COMMIT;
52 '002_pgbench_concurrent_cic' => q(
53 SELECT pg_try_advisory_lock(42)::integer AS gotlock \gset
54 \if :gotlock
55 DROP INDEX CONCURRENTLY idx;
56 CREATE INDEX CONCURRENTLY idx ON tbl(i);
57 SELECT bt_index_check('idx',true);
58 SELECT pg_advisory_unlock(42);
59 \endif
61 });
63 $node->stop;
64 done_testing();