99use PostgreSQL::Test::Cluster;
1010use PostgreSQL::Test::Utils;
1111use Test::More;
12+ use Time::HiRes qw( usleep) ;
1213
1314sub test_tablespace
1415{
@@ -36,14 +37,13 @@ sub test_tablespace
3637 has_streaming => 1);
3738 $node_standby -> append_conf(' postgresql.conf' ,
3839 " allow_in_place_tablespaces = on" );
40+ $node_standby -> append_conf(' postgresql.conf' ,
41+ " primary_slot_name = slot" );
3942 $node_standby -> start;
4043
41- # Make sure connection is made
42- $node_primary -> poll_query_until(' postgres' ,
43- ' SELECT count(*) = 1 FROM pg_stat_replication' );
44- $node_primary -> safe_psql(' postgres' , " SELECT pg_drop_replication_slot('slot')" );
45-
46- $node_standby -> safe_psql(' postgres' , ' CHECKPOINT' );
44+ # Make sure the connection is made
45+ $node_primary -> wait_for_catchup($node_standby , ' write' ,
46+ $node_primary -> lsn(' write' ));
4747
4848 # Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
4949 # DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
@@ -62,10 +62,10 @@ sub test_tablespace
6262 DROP TABLESPACE source_ts;
6363 DROP DATABASE template_db;
6464 ] ;
65-
6665 $query =~ s / <STRATEGY>/ $strategy / g ;
66+
6767 $node_primary -> safe_psql(' postgres' , $query );
68- $node_primary -> wait_for_catchup($node_standby , ' replay ' ,
68+ $node_primary -> wait_for_catchup($node_standby , ' write ' ,
6969 $node_primary -> lsn(' write' ));
7070
7171 # show "create missing directory" log message
@@ -119,7 +119,7 @@ sub test_tablespace
119119my $tspdir = $node_standby -> data_dir . " /pg_tblspc/$tspoid " ;
120120File::Path::rmtree($tspdir );
121121
122- my $logstart = get_log_size( $node_standby ) ;
122+ my $logstart = -s $node_standby -> logfile ;
123123
124124# Create a database in the tablespace and a table in default tablespace
125125$node_primary -> safe_psql(
@@ -133,39 +133,26 @@ sub test_tablespace
133133# Standby should fail and should not silently skip replaying the wal
134134# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
135135# Check the log messages instead of confirming standby failure.
136- my $max_attempts = $PostgreSQL::Test::Utils::timeout_default ;
136+ my $max_attempts = $PostgreSQL::Test::Utils::timeout_default * 10 ;
137137while ($max_attempts -- >= 0)
138138{
139139 last
140140 if (
141141 find_in_log(
142142 $node_standby , qr ! WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/! ,
143143 $logstart ));
144- sleep 1 ;
144+ usleep(100_000) ;
145145}
146146ok($max_attempts > 0, " invalid directory creation is detected" );
147147
148148done_testing();
149149
150-
151- # return the size of logfile of $node in bytes
152- sub get_log_size
153- {
154- my ($node ) = @_ ;
155-
156- return (stat $node -> logfile)[7];
157- }
158-
159150# find $pat in logfile of $node after $off-th byte
160151sub find_in_log
161152{
162153 my ($node , $pat , $off ) = @_ ;
163154
164- $off = 0 unless defined $off ;
165- my $log = PostgreSQL::Test::Utils::slurp_file($node -> logfile);
166- return 0 if (length ($log ) <= $off );
167-
168- $log = substr ($log , $off );
155+ my $log = PostgreSQL::Test::Utils::slurp_file($node -> logfile, $off );
169156
170157 return $log =~ m /$pat / ;
171158}
0 commit comments