Skip to content

Commit e988878

Browse files
committed
Fix pgbench TAP test failure with funky file names (redux)
This test fails if the containing directory contains a funny character such as a space or some perl metacharacter. To avoid that, we check for files names using readdir and a regex, rather than using a glob pattern. Discussion: https://postgr.es/m/CAM6_UM6dGdU39PKAC24T+HD9ouy0jLN9vH6163K8QEEzr__iZw@mail.gmail.com Author: Fabien COELHO Reviewed-by: Raúl Marín Rodríguez
1 parent 9b1384d commit e988878

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

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

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010
$node->init;
1111
$node->start;
1212

13-
# invoke pgbench
13+
# invoke pgbench, with parameters:
14+
# $opts: options as a string to be split on spaces
15+
# $stat: expected exit status
16+
# $out: reference to a regexp list that must match stdout
17+
# $err: reference to a regexp list that must match stderr
18+
# $name: name of test for error messages
19+
# $files: reference to filename/contents dictionnary
20+
# @args: further raw options or arguments
1421
sub pgbench
1522
{
1623
local $Test::Builder::Level = $Test::Builder::Level + 1;
1724

18-
my ($opts, $stat, $out, $err, $name, $files) = @_;
25+
my ($opts, $stat, $out, $err, $name, $files, @args) = @_;
1926
my @cmd = ('pgbench', split /\s+/, $opts);
2027
my @filenames = ();
2128
if (defined $files)
@@ -40,6 +47,9 @@ sub pgbench
4047
append_to_file($filename, $$files{$fn});
4148
}
4249
}
50+
51+
push @cmd, @args;
52+
4353
$node->command_checks_all(\@cmd, $stat, $out, $err, $name);
4454

4555
# cleanup?
@@ -868,20 +878,32 @@ sub pgbench
868878
qr{type: .*/001_pgbench_sleep},
869879
qr{above the 1.0 ms latency limit: [01]/}
870880
],
871-
[qr{^$}i],
881+
[qr{^$}],
872882
'pgbench late throttling',
873883
{ '001_pgbench_sleep' => q{\sleep 2ms} });
874884

885+
# return a list of files from directory $dir matching regexpr $re
886+
# this works around glob portability and escaping issues
887+
sub list_files
888+
{
889+
my ($dir, $re) = @_;
890+
opendir my $dh, $dir or die "cannot opendir $dir: $!";
891+
my @files = grep /$re/, readdir $dh;
892+
closedir $dh or die "cannot closedir $dir: $!";
893+
return map { $dir . '/' . $_ } @files;
894+
}
895+
875896
# check log contents and cleanup
876897
sub check_pgbench_logs
877898
{
878899
local $Test::Builder::Level = $Test::Builder::Level + 1;
879900

880-
my ($prefix, $nb, $min, $max, $re) = @_;
901+
my ($dir, $prefix, $nb, $min, $max, $re) = @_;
881902

882-
my @logs = glob "$prefix.*";
903+
# $prefix is simple enough, thus does not need escaping
904+
my @logs = list_files($dir, qr{^$prefix\..*$});
883905
ok(@logs == $nb, "number of log files");
884-
ok(grep(/^$prefix\.\d+(\.\d+)?$/, @logs) == $nb, "file name format");
906+
ok(grep(/\/$prefix\.\d+(\.\d+)?$/, @logs) == $nb, "file name format");
885907

886908
my $log_number = 0;
887909
for my $log (sort @logs)
@@ -905,22 +927,25 @@ sub check_pgbench_logs
905927

906928
# with sampling rate
907929
pgbench(
908-
"-n -S -t 50 -c 2 --log --log-prefix=$bdir/001_pgbench_log_2 --sampling-rate=0.5",
930+
"-n -S -t 50 -c 2 --log --sampling-rate=0.5",
909931
0,
910932
[ qr{select only}, qr{processed: 100/100} ],
911-
[qr{^$}],
912-
'pgbench logs');
933+
[ qr{^$} ],
934+
'pgbench logs',
935+
undef,
936+
"--log-prefix=$bdir/001_pgbench_log_2");
913937

914-
check_pgbench_logs("$bdir/001_pgbench_log_2", 1, 8, 92,
938+
check_pgbench_logs($bdir, '001_pgbench_log_2', 1, 8, 92,
915939
qr{^0 \d{1,2} \d+ \d \d+ \d+$});
916940

917941
# check log file in some detail
918942
pgbench(
919-
"-n -b se -t 10 -l --log-prefix=$bdir/001_pgbench_log_3",
920-
0, [ qr{select only}, qr{processed: 10/10} ],
921-
[qr{^$}], 'pgbench logs contents');
943+
"-n -b se -t 10 -l",
944+
0, [ qr{select only}, qr{processed: 10/10} ], [ qr{^$} ],
945+
'pgbench logs contents', undef,
946+
"--log-prefix=$bdir/001_pgbench_log_3");
922947

923-
check_pgbench_logs("$bdir/001_pgbench_log_3", 1, 10, 10,
948+
check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
924949
qr{^\d \d{1,2} \d+ \d \d+ \d+$});
925950

926951
# done

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy