This is an automated email from the ASF dual-hosted git repository. tuhaihe pushed a commit to branch REL_2_STABLE in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit c78cbdf712b695832f214a79fec2f41afe279e39 Author: Michael Paquier <[email protected]> AuthorDate: Fri Jun 9 11:56:27 2023 +0900 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__pevvh9u3u...@mail.gmail.com Backpatch-through: 11 (cherry picked from commit 392ea0c78fdb6cb92f1af0793f6c2d48526e6fed) --- src/test/perl/PostgresNode.pm | 16 +++++++++++++++ src/test/recovery/t/019_replslot_limit.pl | 31 +++++++---------------------- src/test/recovery/t/033_replay_tsp_drops.pl | 29 +++------------------------ 3 files changed, 26 insertions(+), 50 deletions(-) diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index b81f6e7b68d..0613823a1a9 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -2764,6 +2764,22 @@ sub log_check =pod +=item log_contains(pattern, offset) + +Find pattern in logfile of node after offset byte. + +=cut + +sub log_contains +{ + my ($self, $pattern, $offset) = @_; + + return TestLib::slurp_file($self->logfile, $offset) =~ + m/$pattern/; +} + +=pod + =item $node->run_log(...) Runs a shell command like TestLib::run_log, but with connection parameters set diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index b365fcc8863..648cab393ea 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -172,8 +172,7 @@ $node_primary->wait_for_catchup($node_standby, 'replay', $start_lsn); $node_standby->stop; -ok( !find_in_log( - $node_standby, +ok( !$node_standby->log_contains( "requested WAL segment [0-9A-F]+ has already been removed"), 'check that required WAL segments are still available'); @@ -195,8 +194,7 @@ $node_primary->safe_psql('postgres', "CHECKPOINT;"); my $invalidated = 0; for (my $i = 0; $i < 10000; $i++) { - if (find_in_log( - $node_primary, + if ($node_primary->log_contains( "invalidating slot \"rep1\" because its restart_lsn [0-9A-F/]+ exceeds max_slot_wal_keep_size", $logstart)) { @@ -219,7 +217,7 @@ is($result, "rep1|f|t|lost|", my $checkpoint_ended = 0; for (my $i = 0; $i < 10000; $i++) { - if (find_in_log($node_primary, "checkpoint complete: ", $logstart)) + if ($node_primary->log_contains("checkpoint complete: ", $logstart)) { $checkpoint_ended = 1; last; @@ -249,8 +247,7 @@ $node_standby->start; my $failed = 0; for (my $i = 0; $i < 10000; $i++) { - if (find_in_log( - $node_standby, + if ($node_standby->log_contains( "requested WAL segment [0-9A-F]+ has already been removed", $logstart)) { @@ -356,8 +353,7 @@ advance_wal($node_primary3, 2); my $max_attempts = $TestLib::timeout_default; while ($max_attempts-- >= 0) { - if (find_in_log( - $node_primary3, + if ($node_primary3->log_contains( "terminating process $senderpid to release replication slot \"rep3\"", $logstart)) { @@ -379,8 +375,7 @@ $node_primary3->poll_query_until('postgres', $max_attempts = $TestLib::timeout_default; while ($max_attempts-- >= 0) { - if (find_in_log( - $node_primary3, + if ($node_primary3->log_contains( 'invalidating slot "rep3" because its restart_lsn', $logstart)) { ok(1, "slot invalidation logged"); @@ -418,16 +413,4 @@ sub get_log_size return (stat $node->logfile)[7]; } -# find $pat in logfile of $node after $off-th byte -sub find_in_log -{ - my ($node, $pat, $off) = @_; - - $off = 0 unless defined $off; - my $log = TestLib::slurp_file($node->logfile); - return 0 if (length($log) <= $off); - - $log = substr($log, $off); - - return $log =~ m/$pat/; -} +done_testing(); diff --git a/src/test/recovery/t/033_replay_tsp_drops.pl b/src/test/recovery/t/033_replay_tsp_drops.pl index fb0b6150f27..ac7b8fe6e4e 100644 --- a/src/test/recovery/t/033_replay_tsp_drops.pl +++ b/src/test/recovery/t/033_replay_tsp_drops.pl @@ -113,7 +113,7 @@ my $tspoid = $node_standby->safe_psql('postgres', my $tspdir = $node_standby->data_dir . "/pg_tblspc/$tspoid"; File::Path::rmtree($tspdir); -my $logstart = get_log_size($node_standby); +my $logstart = -s $node_standby->logfile; # Create a database in the tablespace and a table in default tablespace $node_primary->safe_psql( @@ -132,34 +132,11 @@ while ($max_attempts-- >= 0) { last if ( - find_in_log( - $node_standby, "WARNING: creating missing directory: pg_tblspc/", + $node_standby->log_contains( + qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!, $logstart)); sleep 1; } ok($max_attempts > 0, "invalid directory creation is detected"); done_testing(); - - -# return the size of logfile of $node in bytes -sub get_log_size -{ - my ($node) = @_; - - return (stat $node->logfile)[7]; -} - -# find $pat in logfile of $node after $off-th byte -sub find_in_log -{ - my ($node, $pat, $off) = @_; - - $off = 0 unless defined $off; - my $log = PostgreSQL::Test::Utils::slurp_file($node->logfile); - return 0 if (length($log) <= $off); - - $log = substr($log, $off); - - return $log =~ m/$pat/; -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
