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

Commitd380ec9

Browse files
committed
Allow TestLib::slurp_file to skip contents, and use as needed
In order to avoid getting old logfile contents certain functions inPostgresNode were doing one of two things. On Windows it rotated thelogfile and restarted the server, while elsewhere it truncated the logfile. Both of these are unnecessary. We borrow from the buildfarm whichdoes this instead: note the size of the logfile before we start, andthen when fetching the logfile skip to that position before accumulatingcontents. This is spelled differently on Windows but the effect is thesame. This is largely centralized in TestLib's slurp_file function,which has a new optional parameter, the offset to skip to beforestarting to reading the file. Code in the client becomes much neater.Backpatch to all live branches.Michael Paquier, slightly modified by me.Discussion:https://postgr.es/m/YHajnhcMAI3++pJL@paquier.xyz
1 parent26cf324 commitd380ec9

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,9 +1673,6 @@ sub command_checks_all
16731673
Run a command on the node, then verify that $expected_sql appears in the
16741674
server log file.
16751675
1676-
Reads the whole log file so be careful when working with large log outputs.
1677-
The log file is truncated prior to running the command, however.
1678-
16791676
=cut
16801677

16811678
subissues_sql_like
@@ -1687,10 +1684,11 @@ sub issues_sql_like
16871684
local$ENV{PGHOST} =$self->host;
16881685
local$ENV{PGPORT} =$self->port;
16891686

1690-
truncate$self->logfile, 0;
1687+
my$log_location =-s$self->logfile;
1688+
16911689
my$result = TestLib::run_log($cmd);
16921690
ok($result,"@$cmd exit code 0");
1693-
my$log = TestLib::slurp_file($self->logfile);
1691+
my$log = TestLib::slurp_file($self->logfile,$log_location);
16941692
like($log,$expected_sql,"$test_name: SQL found in server log");
16951693
return;
16961694
}

‎src/test/perl/TestLib.pm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use warnings;
1313
use Config;
1414
use Cwd;
1515
use Exporter'import';
16-
use Fcntlqw(:mode);
16+
use Fcntlqw(:mode :seek);
1717
use File::Basename;
1818
use File::Find;
1919
use File::Spec;
@@ -82,7 +82,7 @@ BEGIN
8282
if ($windows_os)
8383
{
8484
require Win32API::File;
85-
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
85+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer));
8686
}
8787
}
8888

@@ -259,13 +259,18 @@ sub slurp_dir
259259

260260
subslurp_file
261261
{
262-
my ($filename) =@_;
262+
my ($filename,$offset) =@_;
263263
local$/;
264264
my$contents;
265265
if ($Config{osname}ne'MSWin32')
266266
{
267267
open(my$in,'<',$filename)
268268
ordie"could not read\"$filename\":$!";
269+
if (defined($offset))
270+
{
271+
seek($in,$offset, SEEK_SET)
272+
ordie"could not seek\"$filename\":$!";
273+
}
269274
$contents = <$in>;
270275
close$in;
271276
}
@@ -275,6 +280,11 @@ sub slurp_file
275280
ordie"could not open\"$filename\": $^E";
276281
OsFHandleOpen(my$fh = IO::Handle->new(),$fHandle,'r')
277282
ordie"could not read\"$filename\": $^E\n";
283+
if (defined($offset))
284+
{
285+
setFilePointer($fh,$offset,qw(FILE_BEGIN))
286+
ordie"could not seek\"$filename\": $^E\n";
287+
}
278288
$contents = <$fh>;
279289
CloseHandle($fHandle)
280290
ordie"could not close\"$filename\": $^E\n";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp