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

Commita9231fe

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 parent1536e32 commita9231fe

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,21 @@ sub issues_sql_like
20812081

20822082
=pod
20832083
2084+
=item$node->log_contains(pattern, offset)
2085+
2086+
Find pattern in logfile of node after offset byte.
2087+
2088+
=cut
2089+
2090+
sublog_contains
2091+
{
2092+
my ($self,$pattern,$offset) =@_;
2093+
2094+
return TestLib::slurp_file($self->logfile,$offset) =~m/$pattern/;
2095+
}
2096+
2097+
=pod
2098+
20842099
=item$node->run_log(...)
20852100
20862101
Runs a shell command like TestLib::run_log, but with connection parameters set

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@
165165

166166
$node_standby->stop;
167167

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

@@ -188,8 +187,7 @@
188187
my$invalidated = 0;
189188
for (my$i = 0;$i < 10000;$i++)
190189
{
191-
if (find_in_log(
192-
$node_master,
190+
if ($node_master->log_contains(
193191
"invalidating slot\"rep1\" because its restart_lsn [0-9A-F/]+ exceeds max_slot_wal_keep_size",
194192
$logstart))
195193
{
@@ -212,7 +210,7 @@
212210
my$checkpoint_ended = 0;
213211
for (my$i = 0;$i < 10000;$i++)
214212
{
215-
if (find_in_log($node_master,"checkpoint complete:",$logstart))
213+
if ($node_master->log_contains("checkpoint complete:",$logstart))
216214
{
217215
$checkpoint_ended = 1;
218216
last;
@@ -242,8 +240,7 @@
242240
my$failed = 0;
243241
for (my$i = 0;$i < 10000;$i++)
244242
{
245-
if (find_in_log(
246-
$node_standby,
243+
if ($node_standby->log_contains(
247244
"requested WAL segment [0-9A-F]+ has already been removed",
248245
$logstart))
249246
{
@@ -318,17 +315,3 @@ sub get_log_size
318315

319316
return (stat$node->logfile)[7];
320317
}
321-
322-
# find $pat in logfile of $node after $off-th byte
323-
subfind_in_log
324-
{
325-
my ($node,$pat,$off) =@_;
326-
327-
$off = 0unlessdefined$off;
328-
my$log = TestLib::slurp_file($node->logfile);
329-
return 0if (length($log) <=$off);
330-
331-
$log =substr($log,$off);
332-
333-
return$log =~m/$pat/;
334-
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,11 @@ sub test_tablespace
132132
{
133133
last
134134
if (
135-
find_in_log(
136-
$node_standby,qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
135+
$node_standby->log_contains(
136+
qr!WARNING: ( [A-Z0-9]+:)? creating missing directory: pg_tblspc/!,
137137
$logstart));
138138
usleep(100_000);
139139
}
140140
ok($max_attempts > 0,"invalid directory creation is detected");
141141

142142
done_testing();
143-
144-
# find $pat in logfile of $node after $off-th byte
145-
subfind_in_log
146-
{
147-
my ($node,$pat,$off) =@_;
148-
149-
my$log = PostgreSQL::Test::Utils::slurp_file($node->logfile,$off);
150-
151-
return$log =~m/$pat/;
152-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp