99use PostgreSQL::Test::Cluster;
1010use PostgreSQL::Test::Utils;
1111use Test::More;
12+ use Time::HiResqw( usleep) ;
1213
1314sub test_tablespace
1415{
@@ -34,14 +35,13 @@ sub test_tablespace
3435has_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
113113my $tspdir =$node_standby -> data_dir ." /pg_tblspc/$tspoid " ;
114114File::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 ;
131131while ($max_attempts -- >= 0)
132132{
133133last
134134if (
135135find_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}
140140ok($max_attempts > 0," invalid directory creation is detected" );
141141
142142done_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
154145sub find_in_log
155146{
156147my ($node ,$pat ,$off ) =@_ ;
157148
158- $off = 0unless defined $off ;
159- my $log = PostgreSQL::Test::Utils::slurp_file($node -> logfile);
160- return 0if (length ($log ) <=$off );
161-
162- $log =substr ($log ,$off );
149+ my $log = PostgreSQL::Test::Utils::slurp_file($node -> logfile,$off );
163150
164151return $log =~m /$pat / ;
165152}