Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1b864e

Browse files
committed
Fix pgbench TAP test failure with funky file names (redux)
This test fails if the containing directory contains a funny charactersuch as a space or some perl metacharacter. To avoid that, we check forfiles names using readdir and a regex, rather than using a glob pattern.Discussion:https://postgr.es/m/CAM6_UM6dGdU39PKAC24T+HD9ouy0jLN9vH6163K8QEEzr__iZw@mail.gmail.comAuthor: Fabien COELHOReviewed-by: Raúl Marín Rodríguez
1 parent8722c4d commitf1b864e

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,10 +10,17 @@
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
subpgbench
1522
{
16-
my ($opts,$stat,$out,$err,$name,$files) =@_;
23+
my ($opts,$stat,$out,$err,$name,$files,@args) =@_;
1724
my@cmd = ('pgbench',split /\s+/,$opts);
1825
my@filenames = ();
1926
if (defined$files)
@@ -38,6 +45,9 @@ sub pgbench
3845
append_to_file($filename,$$files{$fn});
3946
}
4047
}
48+
49+
push@cmd,@args;
50+
4151
$node->command_checks_all(\@cmd,$stat,$out,$err,$name);
4252

4353
# cleanup?
@@ -791,18 +801,30 @@ sub pgbench
791801
qr{type: .*/001_pgbench_sleep},
792802
qr{above the 1.0 ms latency limit: [01]/}
793803
],
794-
[qr{^$}i],
804+
[qr{^$}],
795805
'pgbench late throttling',
796806
{'001_pgbench_sleep'=>q{\sleep 2ms} });
797807

808+
# return a list of files from directory $dir matching regexpr $re
809+
# this works around glob portability and escaping issues
810+
sublist_files
811+
{
812+
my ($dir,$re) =@_;
813+
opendirmy$dh,$dirordie"cannot opendir$dir:$!";
814+
my@files =grep /$re/,readdir$dh;
815+
closedir$dhordie"cannot closedir$dir:$!";
816+
returnmap {$dir .'/' .$_ }@files;
817+
}
818+
798819
# check log contents and cleanup
799820
subcheck_pgbench_logs
800821
{
801-
my ($prefix,$nb,$min,$max,$re) =@_;
822+
my ($dir,$prefix,$nb,$min,$max,$re) =@_;
802823

803-
my@logs =glob"$prefix.*";
824+
# $prefix is simple enough, thus does not need escaping
825+
my@logs = list_files($dir,qr{^$prefix\..*$});
804826
ok(@logs ==$nb,"number of log files");
805-
ok(grep(/^$prefix\.\d+(\.\d+)?$/,@logs) ==$nb,"file name format");
827+
ok(grep(/\/$prefix\.\d+(\.\d+)?$/,@logs) ==$nb,"file name format");
806828

807829
my$log_number = 0;
808830
formy$log (sort@logs)
@@ -826,22 +848,25 @@ sub check_pgbench_logs
826848

827849
# with sampling rate
828850
pgbench(
829-
"-n -S -t 50 -c 2 --log --log-prefix=$bdir/001_pgbench_log_2 --sampling-rate=0.5",
851+
"-n -S -t 50 -c 2 --log --sampling-rate=0.5",
830852
0,
831853
[qr{select only},qr{processed: 100/100} ],
832-
[qr{^$}],
833-
'pgbench logs');
854+
[qr{^$} ],
855+
'pgbench logs',
856+
undef,
857+
"--log-prefix=$bdir/001_pgbench_log_2");
834858

835-
check_pgbench_logs("$bdir/001_pgbench_log_2", 1, 8, 92,
859+
check_pgbench_logs($bdir,'001_pgbench_log_2', 1, 8, 92,
836860
qr{^0\d{1,2}\d+\d\d+\d+$});
837861

838862
# check log file in some detail
839863
pgbench(
840-
"-n -b se -t 10 -l --log-prefix=$bdir/001_pgbench_log_3",
841-
0, [qr{select only},qr{processed: 10/10} ],
842-
[qr{^$}],'pgbench logs contents');
864+
"-n -b se -t 10 -l",
865+
0, [qr{select only},qr{processed: 10/10} ], [qr{^$} ],
866+
'pgbench logs contents',undef,
867+
"--log-prefix=$bdir/001_pgbench_log_3");
843868

844-
check_pgbench_logs("$bdir/001_pgbench_log_3", 1, 10, 10,
869+
check_pgbench_logs($bdir,'001_pgbench_log_3', 1, 10, 10,
845870
qr{^\d\d{1,2}\d+\d\d+\d+$});
846871

847872
# done

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp