Skip to content

Commit c13585f

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 8021770 commit c13585f

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
@@ -1173,7 +1173,12 @@ sub list_files
11731173
return map { $dir . '/' . $_ } @files;
11741174
}
11751175

1176-
# check log contents and cleanup
1176+
# Check log contents and clean them up:
1177+
# $dir: directory holding logs
1178+
# $prefix: file prefix for per-thread logs
1179+
# $nb: number of expected files
1180+
# $min/$max: minimum and maximum number of lines in log files
1181+
# $re: regular expression each log line has to match
11771182
sub check_pgbench_logs
11781183
{
11791184
local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -1194,7 +1199,7 @@ sub check_pgbench_logs
11941199
my $clen = @contents;
11951200
ok( $min <= $clen && $clen <= $max,
11961201
"transaction count for $log ($clen)");
1197-
ok( grep($re, @contents) == $clen,
1202+
ok( grep(/$re/, @contents) == $clen,
11981203
"transaction format for $prefix");
11991204
close $fh or die "$@";
12001205
};
@@ -1205,25 +1210,25 @@ sub check_pgbench_logs
12051210

12061211
my $bdir = $node->basedir;
12071212

1208-
# with sampling rate
1213+
# Run with sampling rate, 2 clients with 50 transactions each.
12091214
pgbench(
12101215
"-n -S -t 50 -c 2 --log --sampling-rate=0.5", 0,
12111216
[ qr{select only}, qr{processed: 100/100} ], [qr{^$}],
12121217
'pgbench logs', undef,
12131218
"--log-prefix=$bdir/001_pgbench_log_2");
1214-
1219+
# The IDs of the clients (1st field) in the logs should be either 0 or 1.
12151220
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
1216-
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
1221+
qr{^[01] \d{1,2} \d+ \d \d+ \d+$});
12171222

1218-
# check log file in some detail
1223+
# Run with different read-only option pattern, 1 client with 10 transactions.
12191224
pgbench(
1220-
"-n -b se -t 10 -l", 0,
1225+
"-n -b select-only -t 10 -l", 0,
12211226
[ qr{select only}, qr{processed: 10/10} ], [qr{^$}],
12221227
'pgbench logs contents', undef,
12231228
"--log-prefix=$bdir/001_pgbench_log_3");
1224-
1229+
# The ID of a single client (1st field) should match 0.
12251230
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
1226-
qr{^\d \d{1,2} \d+ \d \d+ \d+$});
1231+
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
12271232

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

0 commit comments

Comments
 (0)