Skip to content

Commit 7a9eaf1

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 56e366f commit 7a9eaf1

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
@@ -1043,7 +1043,12 @@ sub list_files
10431043
return map { $dir . '/' . $_ } @files;
10441044
}
10451045

1046-
# check log contents and cleanup
1046+
# Check log contents and clean them up:
1047+
# $dir: directory holding logs
1048+
# $prefix: file prefix for per-thread logs
1049+
# $nb: number of expected files
1050+
# $min/$max: minimum and maximum number of lines in log files
1051+
# $re: regular expression each log line has to match
10471052
sub check_pgbench_logs
10481053
{
10491054
local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -1064,7 +1069,7 @@ sub check_pgbench_logs
10641069
my $clen = @contents;
10651070
ok( $min <= $clen && $clen <= $max,
10661071
"transaction count for $log ($clen)");
1067-
ok( grep($re, @contents) == $clen,
1072+
ok( grep(/$re/, @contents) == $clen,
10681073
"transaction format for $prefix");
10691074
close $fh or die "$@";
10701075
};
@@ -1075,25 +1080,25 @@ sub check_pgbench_logs
10751080

10761081
my $bdir = $node->basedir;
10771082

1078-
# with sampling rate
1083+
# Run with sampling rate, 2 clients with 50 transactions each.
10791084
pgbench(
10801085
"-n -S -t 50 -c 2 --log --sampling-rate=0.5", 0,
10811086
[ qr{select only}, qr{processed: 100/100} ], [qr{^$}],
10821087
'pgbench logs', undef,
10831088
"--log-prefix=$bdir/001_pgbench_log_2");
1084-
1089+
# The IDs of the clients (1st field) in the logs should be either 0 or 1.
10851090
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
1086-
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
1091+
qr{^[01] \d{1,2} \d+ \d \d+ \d+$});
10871092

1088-
# check log file in some detail
1093+
# Run with different read-only option pattern, 1 client with 10 transactions.
10891094
pgbench(
1090-
"-n -b se -t 10 -l", 0,
1095+
"-n -b select-only -t 10 -l", 0,
10911096
[ qr{select only}, qr{processed: 10/10} ], [qr{^$}],
10921097
'pgbench logs contents', undef,
10931098
"--log-prefix=$bdir/001_pgbench_log_3");
1094-
1099+
# The ID of a single client (1st field) should match 0.
10951100
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
1096-
qr{^\d \d{1,2} \d+ \d \d+ \d+$});
1101+
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
10971102

10981103
# done
10991104
$node->safe_psql('postgres', 'DROP TABLESPACE regress_pgbench_tap_1_ts');

0 commit comments

Comments
 (0)