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
{
@@ -36,14 +37,13 @@ sub test_tablespace
36
37
has_streaming => 1);
37
38
$node_standby -> append_conf(' postgresql.conf' ,
38
39
" allow_in_place_tablespaces = on" );
40
+ $node_standby -> append_conf(' postgresql.conf' ,
41
+ " primary_slot_name = slot" );
39
42
$node_standby -> start;
40
43
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' ));
47
47
48
48
# Do immediate shutdown just after a sequence of CREATE DATABASE / DROP
49
49
# DATABASE / DROP TABLESPACE. This causes CREATE DATABASE WAL records
@@ -62,10 +62,10 @@ sub test_tablespace
62
62
DROP TABLESPACE source_ts;
63
63
DROP DATABASE template_db;
64
64
] ;
65
-
66
65
$query =~ s / <STRATEGY>/ $strategy / g ;
66
+
67
67
$node_primary -> safe_psql(' postgres' , $query );
68
- $node_primary -> wait_for_catchup($node_standby , ' replay ' ,
68
+ $node_primary -> wait_for_catchup($node_standby , ' write ' ,
69
69
$node_primary -> lsn(' write' ));
70
70
71
71
# show "create missing directory" log message
@@ -119,7 +119,7 @@ sub test_tablespace
119
119
my $tspdir = $node_standby -> data_dir . " /pg_tblspc/$tspoid " ;
120
120
File::Path::rmtree($tspdir );
121
121
122
- my $logstart = get_log_size( $node_standby ) ;
122
+ my $logstart = -s $node_standby -> logfile ;
123
123
124
124
# Create a database in the tablespace and a table in default tablespace
125
125
$node_primary -> safe_psql(
@@ -133,39 +133,26 @@ sub test_tablespace
133
133
# Standby should fail and should not silently skip replaying the wal
134
134
# In this test, PANIC turns into WARNING by allow_in_place_tablespaces.
135
135
# 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 ;
137
137
while ($max_attempts -- >= 0)
138
138
{
139
139
last
140
140
if (
141
141
find_in_log(
142
142
$node_standby , qr ! WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/! ,
143
143
$logstart ));
144
- sleep 1 ;
144
+ usleep(100_000) ;
145
145
}
146
146
ok($max_attempts > 0, " invalid directory creation is detected" );
147
147
148
148
done_testing();
149
149
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
-
159
150
# find $pat in logfile of $node after $off-th byte
160
151
sub find_in_log
161
152
{
162
153
my ($node , $pat , $off ) = @_ ;
163
154
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 );
169
156
170
157
return $log =~ m /$pat / ;
171
158
}
0 commit comments