Skip to content

Commit 3509a06

Browse files
committed
Refactor routine to find single log content pattern in TAP tests
The same routine to check if a specific pattern can be found in the server logs was copied over four different test scripts. This refactors the whole to use a single routine located in PostgreSQL::Test::Cluster, named log_contains, to grab the contents of the server logs and check for a specific pattern. On HEAD, the code previously used assumed that slurp_file() could not handle an undefined offset, setting it to zero, but slurp_file() does do an extra fseek() before retrieving the log contents only if an offset is defined. In two places, the test was retrieving the full log contents with slurp_file() after calling substr() to apply an offset, ignoring that slurp_file() would be able to handle that. Backpatch all the way down to ease the introduction of new tests that could rely on the new routine. Author: Vignesh C Reviewed-by: Andrew Dunstan, Dagfinn Ilmari Mannsåker, Michael Paquier Discussion: https://postgr.es/m/CALDaNm0YSiLpjCmajwLfidQrFOrLNKPQir7s__PeVvh9U3uoTQ@mail.gmail.com Backpatch-through: 11
1 parent 15b7775 commit 3509a06

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/test/perl/PostgresNode.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,21 @@ sub issues_sql_like
19721972

19731973
=pod
19741974
1975+
=item $node->log_contains(pattern, offset)
1976+
1977+
Find pattern in logfile of node after offset byte.
1978+
1979+
=cut
1980+
1981+
sub log_contains
1982+
{
1983+
my ($self, $pattern, $offset) = @_;
1984+
1985+
return TestLib::slurp_file($self->logfile, $offset) =~ m/$pattern/;
1986+
}
1987+
1988+
=pod
1989+
19751990
=item $node->run_log(...)
19761991
19771992
Runs a shell command like TestLib::run_log, but with connection parameters set

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,11 @@ sub test_tablespace
132132
{
133133
last
134134
if (
135-
find_in_log(
136-
$node_standby, qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
135+
$node_standby->log_contains(
136+
qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
137137
$logstart));
138138
usleep(100_000);
139139
}
140140
ok($max_attempts > 0, "invalid directory creation is detected");
141141

142142
done_testing();
143-
144-
# find $pat in logfile of $node after $off-th byte
145-
sub find_in_log
146-
{
147-
my ($node, $pat, $off) = @_;
148-
149-
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile, $off);
150-
151-
return $log =~ m/$pat/;
152-
}

0 commit comments

Comments
 (0)