1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Backport BackgroundPsql perl test module

Backport the new BackgroundPsql modules and the constructor functions,
background_psql() and interactive_psql, to all supported
branches. That makes it easier to backpatch tests that use it.

BackgroundPsql was introduced in version 16. On version 16, this
commit backports just the new timeout argument from master (commit
334f512f45). On older branches, the whole facility. This includes the
change to `use warnings FATAL => 'all'`, which we haven't otherwise
backported, but it seems good to keep the file identical across
branches.

Discussion: https://www.postgresql.org/message-id/b7c64f20-ea01-4f15-9088-0cd6832af149@iki.fi
This commit is contained in:
Heikki Linnakangas
2024-06-27 19:00:59 +03:00
parent 76fda61402
commit d5fd7865f0
8 changed files with 405 additions and 258 deletions

View File

@ -36,63 +36,46 @@ $node->safe_psql('postgres', q(CREATE TABLE tbl(i int)));
# statements.
#
my $main_in = '';
my $main_out = '';
my $main_timer = IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
my $main_h = $node->background_psql('postgres');
my $main_h =
$node->background_psql('postgres', \$main_in, \$main_out,
$main_timer, on_error_stop => 1);
$main_in .= q(
$main_h->query_safe(q(
BEGIN;
INSERT INTO tbl VALUES(0);
\echo syncpoint1
);
pump $main_h until $main_out =~ /syncpoint1/ || $main_timer->is_expired;
));
my $cic_in = '';
my $cic_out = '';
my $cic_timer = IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
my $cic_h =
$node->background_psql('postgres', \$cic_in, \$cic_out,
$cic_timer, on_error_stop => 1);
$cic_in .= q(
my $cic_h = $node->background_psql('postgres');
$cic_h->query_until(qr/start/, q(
\echo start
CREATE INDEX CONCURRENTLY idx ON tbl(i);
);
pump $cic_h until $cic_out =~ /start/ || $cic_timer->is_expired;
));
$main_in .= q(
$main_h->query_safe(q(
PREPARE TRANSACTION 'a';
);
));
$main_in .= q(
$main_h->query_safe(q(
BEGIN;
INSERT INTO tbl VALUES(0);
\echo syncpoint2
);
pump $main_h until $main_out =~ /syncpoint2/ || $main_timer->is_expired;
));
$node->safe_psql('postgres', q(COMMIT PREPARED 'a';));
$main_in .= q(
$main_h->query_safe(q(
PREPARE TRANSACTION 'b';
BEGIN;
INSERT INTO tbl VALUES(0);
\echo syncpoint3
);
pump $main_h until $main_out =~ /syncpoint3/ || $main_timer->is_expired;
));
$node->safe_psql('postgres', q(COMMIT PREPARED 'b';));
$main_in .= q(
$main_h->query_safe(q(
PREPARE TRANSACTION 'c';
COMMIT PREPARED 'c';
);
$main_h->pump_nb;
));
$main_h->finish;
$cic_h->finish;
$main_h->quit;
$cic_h->quit;
$result = $node->psql('postgres', q(SELECT bt_index_check('idx',true)));
is($result, '0', 'bt_index_check after overlapping 2PC');
@ -113,22 +96,15 @@ PREPARE TRANSACTION 'persists_forever';
));
$node->restart;
my $reindex_in = '';
my $reindex_out = '';
my $reindex_timer =
IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
my $reindex_h =
$node->background_psql('postgres', \$reindex_in, \$reindex_out,
$reindex_timer, on_error_stop => 1);
$reindex_in .= q(
my $reindex_h = $node->background_psql('postgres');
$reindex_h->query_until(qr/start/, q(
\echo start
DROP INDEX CONCURRENTLY idx;
CREATE INDEX CONCURRENTLY idx ON tbl(i);
);
pump $reindex_h until $reindex_out =~ /start/ || $reindex_timer->is_expired;
));
$node->safe_psql('postgres', "COMMIT PREPARED 'spans_restart'");
$reindex_h->finish;
$reindex_h->quit;
$result = $node->psql('postgres', q(SELECT bt_index_check('idx',true)));
is($result, '0', 'bt_index_check after 2PC and restart');