pg_combinebackup PITR comparison test fix - Mailing list pgsql-hackers

From Dagfinn Ilmari Mannsåker
Subject pg_combinebackup PITR comparison test fix
Date
Msg-id 87h67653ns.fsf@wibble.ilmari.org
Whole thread Raw
List pgsql-hackers
Hi hackers,

While I was going through the TAP tests to fix the formatting of command
argument lists to be less confusing, I noticed that pg_combinebackup's
002_compare_backups.pl test accidentally ran pg_dumpall twice against
the same database, thus rendering the tests useless.

Fixing that revealed that there is a difference in the dumps: the
tablespaces have different paths.  pg_dumpall doesn't have an option to
map tablespace paths, so instead I used File::Compare::compare_text()
with a custom comparison function to erase the difference.

- ilmari

From d8f186e79fceb881a225c7b612e074d8956da1ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Sat, 14 Dec 2024 21:08:16 +0000
Subject: [PATCH] Fix pg_combinebackup PITR comparison test

The test was creating both the dumps to compare from the same DB, so
would never detect any mismatches.

Fixing that revealed that there is a difference in the dumps: the
tablespaces have different paths.  pg_dumpall doesn't have an option
to map tablespace paths, so use compare_text() with a custom
comparison function to erase the difference.
---
 .../pg_combinebackup/t/002_compare_backups.pl    | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_combinebackup/t/002_compare_backups.pl b/src/bin/pg_combinebackup/t/002_compare_backups.pl
index 63a0255de15..6bf48971734 100644
--- a/src/bin/pg_combinebackup/t/002_compare_backups.pl
+++ b/src/bin/pg_combinebackup/t/002_compare_backups.pl
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings FATAL => 'all';
-use File::Compare;
+use File::Compare qw(compare_text);
 use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
@@ -175,17 +175,23 @@
         $pitr1->connstr('postgres'),
     ],
     'dump from PITR 1');
-$pitr1->command_ok(
+$pitr2->command_ok(
     [
         'pg_dumpall', '-f',
         $dump2, '--no-sync',
         '--no-unlogged-table-data', '-d',
-        $pitr1->connstr('postgres'),
+        $pitr2->connstr('postgres'),
     ],
     'dump from PITR 2');
 
-# Compare the two dumps, there should be no differences.
-my $compare_res = compare($dump1, $dump2);
+# Compare the two dumps, there should be no differences other than
+# the tablespace paths.
+my $compare_res = compare_text(
+    $dump1, $dump2,
+    sub {
+        s{create tablespace .* location '.*/tspitr\K[12]}{N}i for @_;
+        return $_[0] ne $_[1];
+    });
 note($dump1);
 note($dump2);
 is($compare_res, 0, "dumps are identical");
-- 
2.39.5


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Converting contrib SQL functions to new style
Next
From: Tom Lane
Date:
Subject: Re: Converting contrib SQL functions to new style