Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8c5d9cc

Browse files
committed
Improve recently-added test reliability
Commit 59be1c9 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
1 parent 476f9d5 commit 8c5d9cc

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/test/recovery/t/033_replay_tsp_drops.pl

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PostgreSQL::Test::Cluster;
1010
use PostgreSQL::Test::Utils;
1111
use Test::More;
12+
use Time::HiRes qw(usleep);
1213

1314
sub test_tablespace
1415
{
@@ -34,14 +35,13 @@ sub test_tablespace
3435
has_streaming => 1);
3536
$node_standby->append_conf('postgresql.conf',
3637
"allow_in_place_tablespaces = on");
38+
$node_standby->append_conf('postgresql.conf',
39+
"primary_slot_name = slot");
3740
$node_standby->start;
3841

39-
# Make sure connection is made
40-
$node_primary->poll_query_until('postgres',
41-
'SELECT count(*) = 1 FROM pg_stat_replication');
42-
$node_primary->safe_psql('postgres', "SELECT pg_drop_replication_slot('slot')");
43-
44-
$node_standby->safe_psql('postgres', 'CHECKPOINT');
42+
# Make sure the connection is made
43+
$node_primary->wait_for_catchup($node_standby, 'write',
44+
$node_primary->lsn('write'));
4545

4646
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
4747
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
@@ -62,7 +62,7 @@ sub test_tablespace
6262
];
6363

6464
$node_primary->safe_psql('postgres', $query);
65-
$node_primary->wait_for_catchup($node_standby, 'replay',
65+
$node_primary->wait_for_catchup($node_standby, 'write',
6666
$node_primary->lsn('write'));
6767

6868
# show "create missing directory" log message
@@ -113,7 +113,7 @@ sub test_tablespace
113113
my $tspdir = $node_standby->data_dir . "/pg_tblspc/$tspoid";
114114
File::Path::rmtree($tspdir);
115115

116-
my $logstart = get_log_size($node_standby);
116+
my $logstart = -s $node_standby->logfile;
117117

118118
# Create a database in the tablespace and a table in default tablespace
119119
$node_primary->safe_psql(
@@ -127,39 +127,26 @@ sub test_tablespace
127127
# Standby should fail and should not silently skip replaying the wal
128128
# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
129129
# Check the log messages instead of confirming standby failure.
130-
my $max_attempts = $PostgreSQL::Test::Utils::timeout_default;
130+
my $max_attempts = $PostgreSQL::Test::Utils::timeout_default * 10;
131131
while ($max_attempts-- >= 0)
132132
{
133133
last
134134
if (
135135
find_in_log(
136136
$node_standby, qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
137137
$logstart));
138-
sleep 1;
138+
usleep(100_000);
139139
}
140140
ok($max_attempts > 0, "invalid directory creation is detected");
141141

142142
done_testing();
143143

144-
145-
# return the size of logfile of $node in bytes
146-
sub get_log_size
147-
{
148-
my ($node) = @_;
149-
150-
return (stat $node->logfile)[7];
151-
}
152-
153144
# find $pat in logfile of $node after $off-th byte
154145
sub find_in_log
155146
{
156147
my ($node, $pat, $off) = @_;
157148

158-
$off = 0 unless defined $off;
159-
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile);
160-
return 0 if (length($log) <= $off);
161-
162-
$log = substr($log, $off);
149+
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile, $off);
163150

164151
return $log =~ m/$pat/;
165152
}

0 commit comments

Comments
 (0)