mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
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
This commit is contained in:
@@ -69,17 +69,6 @@ sub test_role
|
||||
}
|
||||
}
|
||||
|
||||
# Find $pattern in log file of $node.
|
||||
sub find_in_log
|
||||
{
|
||||
my ($node, $offset, $pattern) = @_;
|
||||
|
||||
my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile, $offset);
|
||||
return 0 if (length($log) <= 0);
|
||||
|
||||
return $log =~ m/$pattern/;
|
||||
}
|
||||
|
||||
my $node = PostgreSQL::Test::Cluster->new('node');
|
||||
$node->init;
|
||||
$node->append_conf('postgresql.conf', "log_connections = on\n");
|
||||
@@ -91,9 +80,9 @@ reset_pg_hba($node, 'peer');
|
||||
# Check if peer authentication is supported on this platform.
|
||||
my $log_offset = -s $node->logfile;
|
||||
$node->psql('postgres');
|
||||
if (find_in_log(
|
||||
$node, $log_offset,
|
||||
qr/peer authentication is not supported on this platform/))
|
||||
if ($node->log_contains(
|
||||
qr/peer authentication is not supported on this platform/,
|
||||
$log_offset))
|
||||
{
|
||||
plan skip_all => 'peer authentication is not supported on this platform';
|
||||
}
|
||||
|
Reference in New Issue
Block a user