aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-10-03 08:27:34 +0900
committerMichael Paquier <michael@paquier.xyz>2023-10-03 08:27:34 +0900
commit6c77bb42ab0eb3f79e934ed3c97568119cca7b5f (patch)
tree1e3fccf503e545cb5b9a9c2cd12c7452ee254af9 /src
parent06c0c36884a5c9ced6d6a90f8b47540464b28e3a (diff)
downloadpostgresql-6c77bb42ab0eb3f79e934ed3c97568119cca7b5f.tar.gz
postgresql-6c77bb42ab0eb3f79e934ed3c97568119cca7b5f.zip
Replace use of stat()[7] by -s switch in TAP tests to retrieve file size
The list form of stat() is an inelegant API as it relies on the position of the file size in the list returned in result. Like in any other places of the tree, replace that with a -s switch instead. Another suggestion from Dagfinn is File::Stat, which we've been already using for some other fields. It really comes down to a matter of taste to choose that over -s, and the latter is more used in the tree. Author: Bertrand Drouvot Reviewed-by: Dagfinn Ilmari Mannsåker Discussion: https://postgr.es/m/b2020df7-d0fc-4ea5-b2a9-7efc6d36b2ac@gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_controldata/t/001_pg_controldata.pl2
-rw-r--r--src/bin/pg_resetwal/t/002_corrupted.pl2
-rw-r--r--src/test/recovery/t/019_replslot_limit.pl14
3 files changed, 5 insertions, 13 deletions
diff --git a/src/bin/pg_controldata/t/001_pg_controldata.pl b/src/bin/pg_controldata/t/001_pg_controldata.pl
index 4918ea89446..9db8015d0b0 100644
--- a/src/bin/pg_controldata/t/001_pg_controldata.pl
+++ b/src/bin/pg_controldata/t/001_pg_controldata.pl
@@ -24,7 +24,7 @@ command_like([ 'pg_controldata', $node->data_dir ],
# check with a corrupted pg_control
my $pg_control = $node->data_dir . '/global/pg_control';
-my $size = (stat($pg_control))[7];
+my $size = -s $pg_control;
open my $fh, '>', $pg_control or BAIL_OUT($!);
binmode $fh;
diff --git a/src/bin/pg_resetwal/t/002_corrupted.pl b/src/bin/pg_resetwal/t/002_corrupted.pl
index 6d19a1efd5a..b3a37728a42 100644
--- a/src/bin/pg_resetwal/t/002_corrupted.pl
+++ b/src/bin/pg_resetwal/t/002_corrupted.pl
@@ -14,7 +14,7 @@ my $node = PostgreSQL::Test::Cluster->new('main');
$node->init;
my $pg_control = $node->data_dir . '/global/pg_control';
-my $size = (stat($pg_control))[7];
+my $size = -s $pg_control;
# Read out the head of the file to get PG_CONTROL_VERSION in
# particular.
diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl
index 33e50ad933b..7d94f157780 100644
--- a/src/test/recovery/t/019_replslot_limit.pl
+++ b/src/test/recovery/t/019_replslot_limit.pl
@@ -173,7 +173,7 @@ $node_primary->safe_psql('postgres',
"ALTER SYSTEM SET max_wal_size='40MB'; SELECT pg_reload_conf()");
# Advance WAL again. The slot loses the oldest segment by the next checkpoint
-my $logstart = get_log_size($node_primary);
+my $logstart = -s $node_primary->logfile;
advance_wal($node_primary, 7);
# Now create another checkpoint and wait until the WARNING is issued
@@ -229,7 +229,7 @@ $node_primary->safe_psql('postgres',
is($oldestseg, $redoseg, "check that segments have been removed");
# The standby no longer can connect to the primary
-$logstart = get_log_size($node_standby);
+$logstart = -s $node_standby->logfile;
$node_standby->start;
my $failed = 0;
@@ -368,7 +368,7 @@ my $receiverpid = $node_standby3->safe_psql('postgres',
"SELECT pid FROM pg_stat_activity WHERE backend_type = 'walreceiver'");
like($receiverpid, qr/^[0-9]+$/, "have walreceiver pid $receiverpid");
-$logstart = get_log_size($node_primary3);
+$logstart = -s $node_primary3->logfile;
# freeze walsender and walreceiver. Slot will still be active, but walreceiver
# won't get anything anymore.
kill 'STOP', $senderpid, $receiverpid;
@@ -433,12 +433,4 @@ sub advance_wal
return;
}
-# return the size of logfile of $node in bytes
-sub get_log_size
-{
- my ($node) = @_;
-
- return (stat $node->logfile)[7];
-}
-
done_testing();