9
9
use PostgreSQL::Test::Cluster;
10
10
use PostgreSQL::Test::Utils;
11
11
use Test::More;
12
+ use Time::HiRes qw( usleep) ;
12
13
13
14
sub test_tablespace
14
15
{
@@ -34,14 +35,13 @@ sub test_tablespace
34
35
has_streaming => 1);
35
36
$node_standby -> append_conf(' postgresql.conf' ,
36
37
" allow_in_place_tablespaces = on" );
38
+ $node_standby -> append_conf(' postgresql.conf' ,
39
+ " primary_slot_name = slot" );
37
40
$node_standby -> start;
38
41
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' ));
45
45
46
46
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
47
47
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
@@ -62,7 +62,7 @@ sub test_tablespace
62
62
] ;
63
63
64
64
$node_primary -> safe_psql(' postgres' , $query );
65
- $node_primary -> wait_for_catchup($node_standby , ' replay ' ,
65
+ $node_primary -> wait_for_catchup($node_standby , ' write ' ,
66
66
$node_primary -> lsn(' write' ));
67
67
68
68
# show "create missing directory" log message
@@ -113,7 +113,7 @@ sub test_tablespace
113
113
my $tspdir = $node_standby -> data_dir . " /pg_tblspc/$tspoid " ;
114
114
File::Path::rmtree($tspdir );
115
115
116
- my $logstart = get_log_size( $node_standby ) ;
116
+ my $logstart = -s $node_standby -> logfile ;
117
117
118
118
# Create a database in the tablespace and a table in default tablespace
119
119
$node_primary -> safe_psql(
@@ -127,39 +127,26 @@ sub test_tablespace
127
127
# Standby should fail and should not silently skip replaying the wal
128
128
# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
129
129
# 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 ;
131
131
while ($max_attempts -- >= 0)
132
132
{
133
133
last
134
134
if (
135
135
find_in_log(
136
136
$node_standby , qr ! WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/! ,
137
137
$logstart ));
138
- sleep 1 ;
138
+ usleep(100_000) ;
139
139
}
140
140
ok($max_attempts > 0, " invalid directory creation is detected" );
141
141
142
142
done_testing();
143
143
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
-
153
144
# find $pat in logfile of $node after $off-th byte
154
145
sub find_in_log
155
146
{
156
147
my ($node , $pat , $off ) = @_ ;
157
148
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 );
163
150
164
151
return $log =~ m /$pat / ;
165
152
}
0 commit comments