From fce041c5223d14b8bc654461e344f098df95c52a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sat, 3 Jun 2023 18:15:42 -0400 Subject: [PATCH v4 3/3] Adjust a bit previous patches ;) --- src/test/authentication/t/003_peer.pl | 4 +- src/test/perl/PostgreSQL/Test/Cluster.pm | 139 +++++++++++--------- src/test/recovery/t/033_replay_tsp_drops.pl | 2 +- 3 files changed, 78 insertions(+), 67 deletions(-) diff --git a/src/test/authentication/t/003_peer.pl b/src/test/authentication/t/003_peer.pl index 2a035c2d0d..d8e4976072 100644 --- a/src/test/authentication/t/003_peer.pl +++ b/src/test/authentication/t/003_peer.pl @@ -81,8 +81,8 @@ reset_pg_hba($node, 'peer'); my $log_offset = -s $node->logfile; $node->psql('postgres'); if ($node->log_contains( - qr/peer authentication is not supported on this platform/), - $log_offset,) + qr/peer authentication is not supported on this platform/, + $log_offset)) { plan skip_all => 'peer authentication is not supported on this platform'; } diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 912892e28b..19cbc46390 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -2168,68 +2168,6 @@ sub pgbench =pod -=item $node->check_connect_log_contents($offset, $test_name, %parameters) - -Check connection log contents. - -=over - -=item $test_name - -Name of test for error messages. - -=item $offset - -Offset of the log file. - -=item log_like => [ qr/required message/ ] - -If given, it must be an array reference containing a list of regular -expressions that must match against the server log, using -C. - -=item log_unlike => [ qr/prohibited message/ ] - -If given, it must be an array reference containing a list of regular -expressions that must NOT match against the server log. They will be -passed to C. - -=back - -=cut - -sub check_connect_log_contents -{ - my ($self, $test_name, $offset, %params) = @_; - - my (@log_like, @log_unlike); - if (defined($params{log_like})) - { - @log_like = @{ $params{log_like} }; - } - if (defined($params{log_unlike})) - { - @log_unlike = @{ $params{log_unlike} }; - } - - if (@log_like or @log_unlike) - { - my $log_contents = - PostgreSQL::Test::Utils::slurp_file($self->logfile, $offset); - - while (my $regex = shift @log_like) - { - like($log_contents, $regex, "$test_name: log matches"); - } - while (my $regex = shift @log_unlike) - { - unlike($log_contents, $regex, "$test_name: log does not match"); - } - } -} - -=pod - =item $node->connect_ok($connstr, $test_name, %params) Attempt a connection with a custom connection string. This is expected @@ -2246,6 +2184,12 @@ instead of the default. If this regular expression is set, matches it with the output generated. +=item log_like => [ qr/required message/ ] + +=item log_unlike => [ qr/prohibited message/ ] + +See C. + =back =cut @@ -2285,7 +2229,7 @@ sub connect_ok is($stderr, "", "$test_name: no stderr"); - $self->check_connect_log_contents($test_name, $log_location, %params); + $self->log_check($test_name, $log_location, %params); } =pod @@ -2301,6 +2245,12 @@ to fail. If this regular expression is set, matches it with the output generated. +=item log_like => [ qr/required message/ ] + +=item log_unlike => [ qr/prohibited message/ ] + +See C. + =back =cut @@ -2327,7 +2277,7 @@ sub connect_fails like($stderr, $params{expected_stderr}, "$test_name: matches"); } - $self->check_connect_log_contents($test_name, $log_location, %params); + $self->log_check($test_name, $log_location, %params); } =pod @@ -2533,6 +2483,67 @@ sub log_content return PostgreSQL::Test::Utils::slurp_file($self->logfile); } +=pod + +=item $node->log_check($offset, $test_name, %parameters) + +Check contents of server logs. + +=over + +=item $test_name + +Name of test for error messages. + +=item $offset + +Offset of the log file. + +=item log_like => [ qr/required message/ ] + +If given, it must be an array reference containing a list of regular +expressions that must match against the server log, using +C. + +=item log_unlike => [ qr/prohibited message/ ] + +If given, it must be an array reference containing a list of regular +expressions that must NOT match against the server log. They will be +passed to C. + +=back + +=cut + +sub log_check +{ + my ($self, $test_name, $offset, %params) = @_; + + my (@log_like, @log_unlike); + if (defined($params{log_like})) + { + @log_like = @{ $params{log_like} }; + } + if (defined($params{log_unlike})) + { + @log_unlike = @{ $params{log_unlike} }; + } + + if (@log_like or @log_unlike) + { + my $log_contents = + PostgreSQL::Test::Utils::slurp_file($self->logfile, $offset); + + while (my $regex = shift @log_like) + { + like($log_contents, $regex, "$test_name: log matches"); + } + while (my $regex = shift @log_unlike) + { + unlike($log_contents, $regex, "$test_name: log does not match"); + } + } +} =pod diff --git a/src/test/recovery/t/033_replay_tsp_drops.pl b/src/test/recovery/t/033_replay_tsp_drops.pl index 307c30bc6b..af97ed9f70 100644 --- a/src/test/recovery/t/033_replay_tsp_drops.pl +++ b/src/test/recovery/t/033_replay_tsp_drops.pl @@ -142,4 +142,4 @@ while ($max_attempts-- >= 0) } ok($max_attempts > 0, "invalid directory creation is detected"); -done_testing(); \ No newline at end of file +done_testing(); -- 2.40.1