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

Commit7fa7911

Browse files
committed
Refactor log check logic for connect_ok/fails in PostgreSQL::Test::Cluster
This commit refactors a bit the code in charge of checking for logpatterns when connections fail or succeed, by moving the log patternchecks into their own routine, for clarity. This has come up assomething to improve while discussing the refactoring of find_in_log().Backpatch down to 14 where these routines are used, to ease theintroduction of new tests that could rely on them.Author: Vignesh C, Michael PaquierDiscussion:https://postgr.es/m/CALDaNm0YSiLpjCmajwLfidQrFOrLNKPQir7s__PeVvh9U3uoTQ@mail.gmail.comBackpatch-through: 14
1 parent0d3093f commit7fa7911

File tree

1 file changed

+66
-56
lines changed

1 file changed

+66
-56
lines changed

‎src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,15 +2222,9 @@ If this regular expression is set, matches it with the output generated.
22222222
22232223
=itemlog_like => [ qr/required message/ ]
22242224
2225-
If given, it must be an array reference containing a list of regular
2226-
expressions that must match against the server log, using
2227-
C<Test::More::like()>.
2228-
22292225
=itemlog_unlike => [ qr/prohibited message/ ]
22302226
2231-
If given, it must be an array reference containing a list of regular
2232-
expressions that must NOT match against the server log. They will be
2233-
passed toC<Test::More::unlike()>.
2227+
SeeC<log_check(...)>.
22342228
22352229
=back
22362230
@@ -2251,16 +2245,6 @@ sub connect_ok
22512245
$sql ="SELECT\$\$connected with$connstr\$\$";
22522246
}
22532247

2254-
my (@log_like,@log_unlike);
2255-
if (defined($params{log_like}))
2256-
{
2257-
@log_like = @{$params{log_like} };
2258-
}
2259-
if (defined($params{log_unlike}))
2260-
{
2261-
@log_unlike = @{$params{log_unlike} };
2262-
}
2263-
22642248
my$log_location =-s$self->logfile;
22652249

22662250
# Never prompt for a password, any callers of this routine should
@@ -2281,20 +2265,7 @@ sub connect_ok
22812265

22822266
is($stderr,"","$test_name: no stderr");
22832267

2284-
if (@log_likeor@log_unlike)
2285-
{
2286-
my$log_contents =
2287-
PostgreSQL::Test::Utils::slurp_file($self->logfile,$log_location);
2288-
2289-
while (my$regex =shift@log_like)
2290-
{
2291-
like($log_contents,$regex,"$test_name: log matches");
2292-
}
2293-
while (my$regex =shift@log_unlike)
2294-
{
2295-
unlike($log_contents,$regex,"$test_name: log does not match");
2296-
}
2297-
}
2268+
$self->log_check($test_name,$log_location,%params);
22982269
}
22992270

23002271
=pod
@@ -2314,7 +2285,7 @@ If this regular expression is set, matches it with the output generated.
23142285
23152286
=itemlog_unlike => [ qr/prohibited message/ ]
23162287
2317-
SeeC<connect_ok(...)>, above.
2288+
SeeC<log_check(...)>.
23182289
23192290
=back
23202291
@@ -2325,16 +2296,6 @@ sub connect_fails
23252296
local$Test::Builder::Level =$Test::Builder::Level + 1;
23262297
my ($self,$connstr,$test_name,%params) =@_;
23272298

2328-
my (@log_like,@log_unlike);
2329-
if (defined($params{log_like}))
2330-
{
2331-
@log_like = @{$params{log_like} };
2332-
}
2333-
if (defined($params{log_unlike}))
2334-
{
2335-
@log_unlike = @{$params{log_unlike} };
2336-
}
2337-
23382299
my$log_location =-s$self->logfile;
23392300

23402301
# Never prompt for a password, any callers of this routine should
@@ -2352,20 +2313,7 @@ sub connect_fails
23522313
like($stderr,$params{expected_stderr},"$test_name: matches");
23532314
}
23542315

2355-
if (@log_likeor@log_unlike)
2356-
{
2357-
my$log_contents =
2358-
PostgreSQL::Test::Utils::slurp_file($self->logfile,$log_location);
2359-
2360-
while (my$regex =shift@log_like)
2361-
{
2362-
like($log_contents,$regex,"$test_name: log matches");
2363-
}
2364-
while (my$regex =shift@log_unlike)
2365-
{
2366-
unlike($log_contents,$regex,"$test_name: log does not match");
2367-
}
2368-
}
2316+
$self->log_check($test_name,$log_location,%params);
23692317
}
23702318

23712319
=pod
@@ -2559,6 +2507,68 @@ sub issues_sql_like
25592507

25602508
=pod
25612509
2510+
=item$node->log_check($offset, $test_name, %parameters)
2511+
2512+
Check contents of server logs.
2513+
2514+
=over
2515+
2516+
=item$test_name
2517+
2518+
Name of test for error messages.
2519+
2520+
=item$offset
2521+
2522+
Offset of the log file.
2523+
2524+
=itemlog_like => [ qr/required message/ ]
2525+
2526+
If given, it must be an array reference containing a list of regular
2527+
expressions that must match against the server log, using
2528+
C<Test::More::like()>.
2529+
2530+
=itemlog_unlike => [ qr/prohibited message/ ]
2531+
2532+
If given, it must be an array reference containing a list of regular
2533+
expressions that must NOT match against the server log. They will be
2534+
passed toC<Test::More::unlike()>.
2535+
2536+
=back
2537+
2538+
=cut
2539+
2540+
sublog_check
2541+
{
2542+
my ($self,$test_name,$offset,%params) =@_;
2543+
2544+
my (@log_like,@log_unlike);
2545+
if (defined($params{log_like}))
2546+
{
2547+
@log_like = @{$params{log_like} };
2548+
}
2549+
if (defined($params{log_unlike}))
2550+
{
2551+
@log_unlike = @{$params{log_unlike} };
2552+
}
2553+
2554+
if (@log_likeor@log_unlike)
2555+
{
2556+
my$log_contents =
2557+
PostgreSQL::Test::Utils::slurp_file($self->logfile,$offset);
2558+
2559+
while (my$regex =shift@log_like)
2560+
{
2561+
like($log_contents,$regex,"$test_name: log matches");
2562+
}
2563+
while (my$regex =shift@log_unlike)
2564+
{
2565+
unlike($log_contents,$regex,"$test_name: log does not match");
2566+
}
2567+
}
2568+
}
2569+
2570+
=pod
2571+
25622572
=item$node->run_log(...)
25632573
25642574
Runs a shell command like PostgreSQL::Test::Utils::run_log, but with connection parameters set

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp