From: Michael Paquier <michael@paquier.xyz>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Subject: File truncation within PostgresNode::issues_sql_like() wrong on Windows
Date: Wed, 14 Apr 2021 17:13:30 +0900
Message-ID: <YHajnhcMAI3++pJL@paquier.xyz> (raw)
Hi all,
As fairywren has proved a couple of days ago, it is not really a good
idea to rely on a file truncation to check for patterns in the logs of
the backend:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2021-04-07%2013%3A29%3A28
Visibly, a logic based on the log file truncation fails on Windows
because of the concurrent access of the backend that outputs its logs
there. In PostgresNode.pm, connect_ok() and connect_access() enforce
a rotation of the log file before restarting the server on Windows to
make sure that a given step does not find logs generated by a previous
test, but that's not the case of issues_sql_like(). Looking at the
existing tests using this routine (src/bin/scripts/), I have found on
test in 090_reindexdb.pl that could lead to a false positive. The
test is marked in the patch attached, just for awareness.
Would there be any objections to change this routine so as we avoid
the file truncation on Windows? The patch attached achieves that.
Any thoughts?
--
Michael
Attachments:
[text/x-diff] tap-sql-like-truncate.patch (1.6K, ../YHajnhcMAI3++pJL@paquier.xyz/2-tap-sql-like-truncate.patch)
download | inline diff:diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.plindex 159b637230..8b06218d6b 100644--- a/src/bin/scripts/t/090_reindexdb.pl+++ b/src/bin/scripts/t/090_reindexdb.pl@@ -174,6 +174,7 @@ $node->command_fails(
$node->command_fails(
[ 'reindexdb', '-j', '2', '-i', 'i1', 'postgres' ],
'parallel reindexdb cannot process indexes');
+# XXX The first query maps with a test above.
$node->issues_sql_like(
[ 'reindexdb', '-j', '2', 'postgres' ],
qr/statement:\ REINDEX SYSTEM postgres;
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pmindex e26b2b3f30..9daa438ccc 100644--- a/src/test/perl/PostgresNode.pm+++ b/src/test/perl/PostgresNode.pm@@ -2195,7 +2195,8 @@ Run a command on the node, then verify that $expected_sql appears in the
server log file.
Reads the whole log file so be careful when working with large log outputs.
-The log file is truncated prior to running the command, however.+The log file is truncated prior to running the command, and on Windows, a+rotation of the log file is done before restarting the node.
=cut
@@ -2207,7 +2208,18 @@ sub issues_sql_like
local %ENV = $self->_get_env();
- truncate $self->logfile, 0;+ # On Windows, the truncation would not work, so rotate the log+ # file before restarting the server afresh.+ if ($TestLib::windows_os)+ {+ $self->rotate_logfile;+ $self->restart;+ }+ else+ {+ truncate $self->logfile, 0;+ }+
my $result = TestLib::run_log($cmd);
ok($result, "@$cmd exit code 0");
my $log = TestLib::slurp_file($self->logfile);
[application/pgp-signature] signature.asc (832B, ../YHajnhcMAI3++pJL@paquier.xyz/3-signature.asc)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, pgsql-hackers@lists.postgresql.org
Subject: Re: File truncation within PostgresNode::issues_sql_like() wrong on Windows
In-Reply-To: <YHajnhcMAI3++pJL@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox