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

Commite480c6d

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 parent0e8acd3 commite480c6d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,6 @@ sub command_checks_all
17811781
Run a command on the node, then verify that $expected_sql appears in the
17821782
server log file.
17831783
1784-
Reads the whole log file so be careful when working with large log outputs.
1785-
The log file is truncated prior to running the command, however.
1786-
17871784
=cut
17881785

17891786
subissues_sql_like
@@ -1795,10 +1792,11 @@ sub issues_sql_like
17951792
local$ENV{PGHOST} =$self->host;
17961793
local$ENV{PGPORT} =$self->port;
17971794

1798-
truncate$self->logfile, 0;
1795+
my$log_location =-s$self->logfile;
1796+
17991797
my$result = TestLib::run_log($cmd);
18001798
ok($result,"@$cmd exit code 0");
1801-
my$log = TestLib::slurp_file($self->logfile);
1799+
my$log = TestLib::slurp_file($self->logfile,$log_location);
18021800
like($log,$expected_sql,"$test_name: SQL found in server log");
18031801
return;
18041802
}

‎src/test/perl/TestLib.pm

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use warnings;
4646
use Config;
4747
use Cwd;
4848
use Exporter'import';
49-
use Fcntlqw(:mode);
49+
use Fcntlqw(:mode :seek);
5050
use File::Basename;
5151
use File::Find;
5252
use File::Spec;
@@ -117,7 +117,7 @@ BEGIN
117117
if ($windows_os)
118118
{
119119
require Win32API::File;
120-
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle));
120+
Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle setFilePointer));
121121
}
122122

123123
# Specifies whether to use Unix sockets for test setups. On
@@ -402,21 +402,27 @@ sub slurp_dir
402402

403403
=pod
404404
405-
=itemslurp_file(filename)
405+
=itemslurp_file(filename [, $offset])
406406
407-
Return the full contents of the specified file.
407+
Return the full contents of the specified file, beginning from an
408+
offset position if specified.
408409
409410
=cut
410411

411412
subslurp_file
412413
{
413-
my ($filename) =@_;
414+
my ($filename,$offset) =@_;
414415
local$/;
415416
my$contents;
416417
if ($Config{osname}ne'MSWin32')
417418
{
418419
open(my$in,'<',$filename)
419420
ordie"could not read\"$filename\":$!";
421+
if (defined($offset))
422+
{
423+
seek($in,$offset, SEEK_SET)
424+
ordie"could not seek\"$filename\":$!";
425+
}
420426
$contents = <$in>;
421427
close$in;
422428
}
@@ -426,6 +432,11 @@ sub slurp_file
426432
ordie"could not open\"$filename\": $^E";
427433
OsFHandleOpen(my$fh = IO::Handle->new(),$fHandle,'r')
428434
ordie"could not read\"$filename\": $^E\n";
435+
if (defined($offset))
436+
{
437+
setFilePointer($fh,$offset,qw(FILE_BEGIN))
438+
ordie"could not seek\"$filename\": $^E\n";
439+
}
429440
$contents = <$fh>;
430441
CloseHandle($fHandle)
431442
ordie"could not close\"$filename\": $^E\n";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp