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

Commit26eaf82

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 parent9a2dbc6 commit26eaf82

File tree

1 file changed

+65
-56
lines changed

1 file changed

+65
-56
lines changed

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

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,15 +2186,9 @@ If this regular expression is set, matches it with the output generated.
21862186
21872187
=itemlog_like => [ qr/required message/ ]
21882188
2189-
If given, it must be an array reference containing a list of regular
2190-
expressions that must match against the server log, using
2191-
C<Test::More::like()>.
2192-
21932189
=itemlog_unlike => [ qr/prohibited message/ ]
21942190
2195-
If given, it must be an array reference containing a list of regular
2196-
expressions that must NOT match against the server log. They will be
2197-
passed toC<Test::More::unlike()>.
2191+
SeeC<log_check(...)>.
21982192
21992193
=back
22002194
@@ -2215,16 +2209,6 @@ sub connect_ok
22152209
$sql ="SELECT\$\$connected with$connstr\$\$";
22162210
}
22172211

2218-
my (@log_like,@log_unlike);
2219-
if (defined($params{log_like}))
2220-
{
2221-
@log_like = @{$params{log_like} };
2222-
}
2223-
if (defined($params{log_unlike}))
2224-
{
2225-
@log_unlike = @{$params{log_unlike} };
2226-
}
2227-
22282212
my$log_location =-s$self->logfile;
22292213

22302214
# Never prompt for a password, any callers of this routine should
@@ -2245,20 +2229,7 @@ sub connect_ok
22452229

22462230
is($stderr,"","$test_name: no stderr");
22472231

2248-
if (@log_likeor@log_unlike)
2249-
{
2250-
my$log_contents =
2251-
PostgreSQL::Test::Utils::slurp_file($self->logfile,$log_location);
2252-
2253-
while (my$regex =shift@log_like)
2254-
{
2255-
like($log_contents,$regex,"$test_name: log matches");
2256-
}
2257-
while (my$regex =shift@log_unlike)
2258-
{
2259-
unlike($log_contents,$regex,"$test_name: log does not match");
2260-
}
2261-
}
2232+
$self->log_check($test_name,$log_location,%params);
22622233
}
22632234

22642235
=pod
@@ -2278,7 +2249,7 @@ If this regular expression is set, matches it with the output generated.
22782249
22792250
=itemlog_unlike => [ qr/prohibited message/ ]
22802251
2281-
SeeC<connect_ok(...)>, above.
2252+
SeeC<log_check(...)>.
22822253
22832254
=back
22842255
@@ -2289,16 +2260,6 @@ sub connect_fails
22892260
local$Test::Builder::Level =$Test::Builder::Level + 1;
22902261
my ($self,$connstr,$test_name,%params) =@_;
22912262

2292-
my (@log_like,@log_unlike);
2293-
if (defined($params{log_like}))
2294-
{
2295-
@log_like = @{$params{log_like} };
2296-
}
2297-
if (defined($params{log_unlike}))
2298-
{
2299-
@log_unlike = @{$params{log_unlike} };
2300-
}
2301-
23022263
my$log_location =-s$self->logfile;
23032264

23042265
# Never prompt for a password, any callers of this routine should
@@ -2316,20 +2277,7 @@ sub connect_fails
23162277
like($stderr,$params{expected_stderr},"$test_name: matches");
23172278
}
23182279

2319-
if (@log_likeor@log_unlike)
2320-
{
2321-
my$log_contents =
2322-
PostgreSQL::Test::Utils::slurp_file($self->logfile,$log_location);
2323-
2324-
while (my$regex =shift@log_like)
2325-
{
2326-
like($log_contents,$regex,"$test_name: log matches");
2327-
}
2328-
while (my$regex =shift@log_unlike)
2329-
{
2330-
unlike($log_contents,$regex,"$test_name: log does not match");
2331-
}
2332-
}
2280+
$self->log_check($test_name,$log_location,%params);
23332281
}
23342282

23352283
=pod
@@ -2535,6 +2483,67 @@ sub log_content
25352483
return PostgreSQL::Test::Utils::slurp_file($self->logfile);
25362484
}
25372485

2486+
=pod
2487+
2488+
=item$node->log_check($offset, $test_name, %parameters)
2489+
2490+
Check contents of server logs.
2491+
2492+
=over
2493+
2494+
=item$test_name
2495+
2496+
Name of test for error messages.
2497+
2498+
=item$offset
2499+
2500+
Offset of the log file.
2501+
2502+
=itemlog_like => [ qr/required message/ ]
2503+
2504+
If given, it must be an array reference containing a list of regular
2505+
expressions that must match against the server log, using
2506+
C<Test::More::like()>.
2507+
2508+
=itemlog_unlike => [ qr/prohibited message/ ]
2509+
2510+
If given, it must be an array reference containing a list of regular
2511+
expressions that must NOT match against the server log. They will be
2512+
passed toC<Test::More::unlike()>.
2513+
2514+
=back
2515+
2516+
=cut
2517+
2518+
sublog_check
2519+
{
2520+
my ($self,$test_name,$offset,%params) =@_;
2521+
2522+
my (@log_like,@log_unlike);
2523+
if (defined($params{log_like}))
2524+
{
2525+
@log_like = @{$params{log_like} };
2526+
}
2527+
if (defined($params{log_unlike}))
2528+
{
2529+
@log_unlike = @{$params{log_unlike} };
2530+
}
2531+
2532+
if (@log_likeor@log_unlike)
2533+
{
2534+
my$log_contents =
2535+
PostgreSQL::Test::Utils::slurp_file($self->logfile,$offset);
2536+
2537+
while (my$regex =shift@log_like)
2538+
{
2539+
like($log_contents,$regex,"$test_name: log matches");
2540+
}
2541+
while (my$regex =shift@log_unlike)
2542+
{
2543+
unlike($log_contents,$regex,"$test_name: log does not match");
2544+
}
2545+
}
2546+
}
25382547

25392548
=pod
25402549

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp