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

Commite25e5f7

Browse files
committed
Refactor routine to find single log content pattern in TAP tests
The same routine to check if a specific pattern can be found in theserver logs was copied over four different test scripts. This refactorsthe whole to use a single routine located in PostgreSQL::Test::Cluster,named log_contains, to grab the contents of the server logs and checkfor a specific pattern.On HEAD, the code previously used assumed that slurp_file() could nothandle an undefined offset, setting it to zero, but slurp_file() doesdo an extra fseek() before retrieving the log contents only if an offsetis defined. In two places, the test was retrieving the full logcontents with slurp_file() after calling substr() to apply an offset,ignoring that slurp_file() would be able to handle that.Backpatch all the way down to ease the introduction of new tests thatcould rely on the new routine.Author: Vignesh CReviewed-by: Andrew Dunstan, Dagfinn Ilmari Mannsåker, Michael PaquierDiscussion:https://postgr.es/m/CALDaNm0YSiLpjCmajwLfidQrFOrLNKPQir7s__PeVvh9U3uoTQ@mail.gmail.comBackpatch-through: 11
1 parent7fa7911 commite25e5f7

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,21 @@ sub log_check
25692569

25702570
=pod
25712571
2572+
=itemlog_contains(pattern, offset)
2573+
2574+
Find pattern in logfile of node after offset byte.
2575+
2576+
=cut
2577+
2578+
sublog_contains
2579+
{
2580+
my ($self,$pattern,$offset) =@_;
2581+
2582+
return PostgreSQL::Test::Utils::slurp_file($self->logfile,$offset) =~m/$pattern/;
2583+
}
2584+
2585+
=pod
2586+
25722587
=item$node->run_log(...)
25732588
25742589
Runs a shell command like PostgreSQL::Test::Utils::run_log, but with connection parameters set

‎src/test/recovery/t/019_replslot_limit.pl

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@
163163

164164
$node_standby->stop;
165165

166-
ok( !find_in_log(
167-
$node_standby,
166+
ok( !$node_standby->log_contains(
168167
"requested WAL segment [0-9A-F]+ has already been removed"),
169168
'check that required WAL segments are still available');
170169

@@ -186,8 +185,7 @@
186185
my$invalidated = 0;
187186
for (my$i = 0;$i < 10000;$i++)
188187
{
189-
if (find_in_log(
190-
$node_primary,
188+
if ($node_primary->log_contains(
191189
"invalidating slot\"rep1\" because its restart_lsn [0-9A-F/]+ exceeds max_slot_wal_keep_size",
192190
$logstart))
193191
{
@@ -210,7 +208,7 @@
210208
my$checkpoint_ended = 0;
211209
for (my$i = 0;$i < 10000;$i++)
212210
{
213-
if (find_in_log($node_primary,"checkpoint complete:",$logstart))
211+
if ($node_primary->log_contains("checkpoint complete:",$logstart))
214212
{
215213
$checkpoint_ended = 1;
216214
last;
@@ -240,8 +238,7 @@
240238
my$failed = 0;
241239
for (my$i = 0;$i < 10000;$i++)
242240
{
243-
if (find_in_log(
244-
$node_standby,
241+
if ($node_standby->log_contains(
245242
"requested WAL segment [0-9A-F]+ has already been removed",
246243
$logstart))
247244
{
@@ -384,8 +381,7 @@
384381
my$max_attempts =$PostgreSQL::Test::Utils::timeout_default;
385382
while ($max_attempts-- >= 0)
386383
{
387-
if (find_in_log(
388-
$node_primary3,
384+
if ($node_primary3->log_contains(
389385
"terminating process$senderpid to release replication slot\"rep3\"",
390386
$logstart))
391387
{
@@ -407,8 +403,7 @@
407403
$max_attempts =$PostgreSQL::Test::Utils::timeout_default;
408404
while ($max_attempts-- >= 0)
409405
{
410-
if (find_in_log(
411-
$node_primary3,
406+
if ($node_primary3->log_contains(
412407
'invalidating slot "rep3" because its restart_lsn',$logstart))
413408
{
414409
ok(1,"slot invalidation logged");
@@ -446,18 +441,4 @@ sub get_log_size
446441
return (stat$node->logfile)[7];
447442
}
448443

449-
# find $pat in logfile of $node after $off-th byte
450-
subfind_in_log
451-
{
452-
my ($node,$pat,$off) =@_;
453-
454-
$off = 0unlessdefined$off;
455-
my$log = PostgreSQL::Test::Utils::slurp_file($node->logfile);
456-
return 0if (length($log) <=$off);
457-
458-
$log =substr($log,$off);
459-
460-
return$log =~m/$pat/;
461-
}
462-
463444
done_testing();

‎src/test/recovery/t/033_replay_tsp_drops.pl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,11 @@ sub test_tablespace
138138
{
139139
last
140140
if (
141-
find_in_log(
142-
$node_standby,qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
141+
$node_standby->log_contains(
142+
qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
143143
$logstart));
144144
usleep(100_000);
145145
}
146146
ok($max_attempts > 0,"invalid directory creation is detected");
147147

148148
done_testing();
149-
150-
# find $pat in logfile of $node after $off-th byte
151-
subfind_in_log
152-
{
153-
my ($node,$pat,$off) =@_;
154-
155-
my$log = PostgreSQL::Test::Utils::slurp_file($node->logfile,$off);
156-
157-
return$log =~m/$pat/;
158-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp