mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-29 22:37:20 +02:00
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
This commit is contained in:
parent
56e366f675
commit
7a9eaf111a
@ -1043,7 +1043,12 @@ sub list_files
|
|||||||
return map { $dir . '/' . $_ } @files;
|
return map { $dir . '/' . $_ } @files;
|
||||||
}
|
}
|
||||||
|
|
||||||
# check log contents and cleanup
|
# Check log contents and clean them up:
|
||||||
|
# $dir: directory holding logs
|
||||||
|
# $prefix: file prefix for per-thread logs
|
||||||
|
# $nb: number of expected files
|
||||||
|
# $min/$max: minimum and maximum number of lines in log files
|
||||||
|
# $re: regular expression each log line has to match
|
||||||
sub check_pgbench_logs
|
sub check_pgbench_logs
|
||||||
{
|
{
|
||||||
local $Test::Builder::Level = $Test::Builder::Level + 1;
|
local $Test::Builder::Level = $Test::Builder::Level + 1;
|
||||||
@ -1064,7 +1069,7 @@ sub check_pgbench_logs
|
|||||||
my $clen = @contents;
|
my $clen = @contents;
|
||||||
ok( $min <= $clen && $clen <= $max,
|
ok( $min <= $clen && $clen <= $max,
|
||||||
"transaction count for $log ($clen)");
|
"transaction count for $log ($clen)");
|
||||||
ok( grep($re, @contents) == $clen,
|
ok( grep(/$re/, @contents) == $clen,
|
||||||
"transaction format for $prefix");
|
"transaction format for $prefix");
|
||||||
close $fh or die "$@";
|
close $fh or die "$@";
|
||||||
};
|
};
|
||||||
@ -1075,25 +1080,25 @@ sub check_pgbench_logs
|
|||||||
|
|
||||||
my $bdir = $node->basedir;
|
my $bdir = $node->basedir;
|
||||||
|
|
||||||
# with sampling rate
|
# Run with sampling rate, 2 clients with 50 transactions each.
|
||||||
pgbench(
|
pgbench(
|
||||||
"-n -S -t 50 -c 2 --log --sampling-rate=0.5", 0,
|
"-n -S -t 50 -c 2 --log --sampling-rate=0.5", 0,
|
||||||
[ qr{select only}, qr{processed: 100/100} ], [qr{^$}],
|
[ qr{select only}, qr{processed: 100/100} ], [qr{^$}],
|
||||||
'pgbench logs', undef,
|
'pgbench logs', undef,
|
||||||
"--log-prefix=$bdir/001_pgbench_log_2");
|
"--log-prefix=$bdir/001_pgbench_log_2");
|
||||||
|
# The IDs of the clients (1st field) in the logs should be either 0 or 1.
|
||||||
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
|
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
|
||||||
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
|
qr{^[01] \d{1,2} \d+ \d \d+ \d+$});
|
||||||
|
|
||||||
# check log file in some detail
|
# Run with different read-only option pattern, 1 client with 10 transactions.
|
||||||
pgbench(
|
pgbench(
|
||||||
"-n -b se -t 10 -l", 0,
|
"-n -b select-only -t 10 -l", 0,
|
||||||
[ qr{select only}, qr{processed: 10/10} ], [qr{^$}],
|
[ qr{select only}, qr{processed: 10/10} ], [qr{^$}],
|
||||||
'pgbench logs contents', undef,
|
'pgbench logs contents', undef,
|
||||||
"--log-prefix=$bdir/001_pgbench_log_3");
|
"--log-prefix=$bdir/001_pgbench_log_3");
|
||||||
|
# The ID of a single client (1st field) should match 0.
|
||||||
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
|
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
|
||||||
qr{^\d \d{1,2} \d+ \d \d+ \d+$});
|
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
|
||||||
|
|
||||||
# done
|
# done
|
||||||
$node->safe_psql('postgres', 'DROP TABLESPACE regress_pgbench_tap_1_ts');
|
$node->safe_psql('postgres', 'DROP TABLESPACE regress_pgbench_tap_1_ts');
|
||||||
|
Loading…
Reference in New Issue
Block a user