Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79ff96a

Browse files
committed
Fix pattern matching logic for logs in TAP tests of pgbench
The logic checking for the format of per-thread logs used grep() with directly "$re", which would cause the test to consider all the logs as a match without caring about their format at all. Using "/$re/" makes grep() perform a regex test, which is what we want here. While on it, improve some of the tests to be more picky with the patterns expected and add more comments to describe the tests. Issue discovered while digging into a separate patch. Author: Fabien Coelho, Michael Paquier Discussion: https://postgr.es/m/YNPsPAUoVDCpPOGk@paquier.xyz Backpatch-through: 11
1 parent 7a48dfb commit 79ff96a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,12 @@ sub list_files
855855
return map { $dir . '/' . $_ } @files;
856856
}
857857

858-
# check log contents and cleanup
858+
# Check log contents and clean them up:
859+
# $dir: directory holding logs
860+
# $prefix: file prefix for per-thread logs
861+
# $nb: number of expected files
862+
# $min/$max: minimum and maximum number of lines in log files
863+
# $re: regular expression each log line has to match
859864
sub check_pgbench_logs
860865
{
861866
local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -876,7 +881,7 @@ sub check_pgbench_logs
876881
my $clen = @contents;
877882
ok( $min <= $clen && $clen <= $max,
878883
"transaction count for $log ($clen)");
879-
ok( grep($re, @contents) == $clen,
884+
ok( grep(/$re/, @contents) == $clen,
880885
"transaction format for $prefix");
881886
close $fh or die "$@";
882887
};
@@ -887,25 +892,25 @@ sub check_pgbench_logs
887892

888893
my $bdir = $node->basedir;
889894

890-
# with sampling rate
895+
# Run with sampling rate, 2 clients with 50 transactions each.
891896
pgbench(
892897
"-n -S -t 50 -c 2 --log --sampling-rate=0.5", 0,
893898
[ qr{select only}, qr{processed: 100/100} ], [qr{^$}],
894899
'pgbench logs', undef,
895900
"--log-prefix=$bdir/001_pgbench_log_2");
896-
901+
# The IDs of the clients (1st field) in the logs should be either 0 or 1.
897902
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
898-
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
903+
qr{^[01] \d{1,2} \d+ \d \d+ \d+$});
899904

900-
# check log file in some detail
905+
# Run with different read-only option pattern, 1 client with 10 transactions.
901906
pgbench(
902-
"-n -b se -t 10 -l", 0,
907+
"-n -b select-only -t 10 -l", 0,
903908
[ qr{select only}, qr{processed: 10/10} ], [qr{^$}],
904909
'pgbench logs contents', undef,
905910
"--log-prefix=$bdir/001_pgbench_log_3");
906-
911+
# The ID of a single client (1st field) should match 0.
907912
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
908-
qr{^\d \d{1,2} \d+ \d \d+ \d+$});
913+
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
909914

910915
# done
911916
$node->stop;

0 commit comments

Comments
 (0)