mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-30 04:37:18 +02:00
Improve recently-added test reliability
Commit 59be1c942a
already tried to make
src/test/recovery/t/033_replay_tsp_drops more reliable, but it wasn't
enough. Try to improve on that by making this use of a replication slot
to be more like others. Also, don't drop the slot.
Make a few other stylistic changes while at it. It's still quite slow,
which is another thing that we need to fix in this script.
Backpatch to all supported branches.
Discussion: https://postgr.es/m/349302.1659191875@sss.pgh.pa.us
This commit is contained in:
parent
476f9d5330
commit
8c5d9ccca9
@ -9,6 +9,7 @@ use warnings;
|
|||||||
use PostgreSQL::Test::Cluster;
|
use PostgreSQL::Test::Cluster;
|
||||||
use PostgreSQL::Test::Utils;
|
use PostgreSQL::Test::Utils;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
use Time::HiRes qw(usleep);
|
||||||
|
|
||||||
sub test_tablespace
|
sub test_tablespace
|
||||||
{
|
{
|
||||||
@ -34,14 +35,13 @@ sub test_tablespace
|
|||||||
has_streaming => 1);
|
has_streaming => 1);
|
||||||
$node_standby->append_conf('postgresql.conf',
|
$node_standby->append_conf('postgresql.conf',
|
||||||
"allow_in_place_tablespaces = on");
|
"allow_in_place_tablespaces = on");
|
||||||
|
$node_standby->append_conf('postgresql.conf',
|
||||||
|
"primary_slot_name = slot");
|
||||||
$node_standby->start;
|
$node_standby->start;
|
||||||
|
|
||||||
# Make sure connection is made
|
# Make sure the connection is made
|
||||||
$node_primary->poll_query_until('postgres',
|
$node_primary->wait_for_catchup($node_standby, 'write',
|
||||||
'SELECT count(*) = 1 FROM pg_stat_replication');
|
$node_primary->lsn('write'));
|
||||||
$node_primary->safe_psql('postgres', "SELECT pg_drop_replication_slot('slot')");
|
|
||||||
|
|
||||||
$node_standby->safe_psql('postgres', 'CHECKPOINT');
|
|
||||||
|
|
||||||
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
|
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
|
||||||
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
|
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
|
||||||
@ -62,7 +62,7 @@ sub test_tablespace
|
|||||||
];
|
];
|
||||||
|
|
||||||
$node_primary->safe_psql('postgres', $query);
|
$node_primary->safe_psql('postgres', $query);
|
||||||
$node_primary->wait_for_catchup($node_standby, 'replay',
|
$node_primary->wait_for_catchup($node_standby, 'write',
|
||||||
$node_primary->lsn('write'));
|
$node_primary->lsn('write'));
|
||||||
|
|
||||||
# show "create missing directory" log message
|
# show "create missing directory" log message
|
||||||
@ -113,7 +113,7 @@ my $tspoid = $node_standby->safe_psql('postgres',
|
|||||||
my $tspdir = $node_standby->data_dir . "/pg_tblspc/$tspoid";
|
my $tspdir = $node_standby->data_dir . "/pg_tblspc/$tspoid";
|
||||||
File::Path::rmtree($tspdir);
|
File::Path::rmtree($tspdir);
|
||||||
|
|
||||||
my $logstart = get_log_size($node_standby);
|
my $logstart = -s $node_standby->logfile;
|
||||||
|
|
||||||
# Create a database in the tablespace and a table in default tablespace
|
# Create a database in the tablespace and a table in default tablespace
|
||||||
$node_primary->safe_psql(
|
$node_primary->safe_psql(
|
||||||
@ -127,7 +127,7 @@ $node_primary->safe_psql(
|
|||||||
# Standby should fail and should not silently skip replaying the wal
|
# Standby should fail and should not silently skip replaying the wal
|
||||||
# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
|
# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
|
||||||
# Check the log messages instead of confirming standby failure.
|
# Check the log messages instead of confirming standby failure.
|
||||||
my $max_attempts = $PostgreSQL::Test::Utils::timeout_default;
|
my $max_attempts = $PostgreSQL::Test::Utils::timeout_default * 10;
|
||||||
while ($max_attempts-- >= 0)
|
while ($max_attempts-- >= 0)
|
||||||
{
|
{
|
||||||
last
|
last
|
||||||
@ -135,31 +135,18 @@ while ($max_attempts-- >= 0)
|
|||||||
find_in_log(
|
find_in_log(
|
||||||
$node_standby, qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
|
$node_standby, qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
|
||||||
$logstart));
|
$logstart));
|
||||||
sleep 1;
|
usleep(100_000);
|
||||||
}
|
}
|
||||||
ok($max_attempts > 0, "invalid directory creation is detected");
|
ok($max_attempts > 0, "invalid directory creation is detected");
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
||||||
|
|
||||||
# return the size of logfile of $node in bytes
|
|
||||||
sub get_log_size
|
|
||||||
{
|
|
||||||
my ($node) = @_;
|
|
||||||
|
|
||||||
return (stat $node->logfile)[7];
|
|
||||||
}
|
|
||||||
|
|
||||||
# find $pat in logfile of $node after $off-th byte
|
# find $pat in logfile of $node after $off-th byte
|
||||||
sub find_in_log
|
sub find_in_log
|
||||||
{
|
{
|
||||||
my ($node, $pat, $off) = @_;
|
my ($node, $pat, $off) = @_;
|
||||||
|
|
||||||
$off = 0 unless defined $off;
|
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile, $off);
|
||||||
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile);
|
|
||||||
return 0 if (length($log) <= $off);
|
|
||||||
|
|
||||||
$log = substr($log, $off);
|
|
||||||
|
|
||||||
return $log =~ m/$pat/;
|
return $log =~ m/$pat/;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user