Skip invalid database pg_upgrade test on obsolete servers
authorAlvaro Herrera <[email protected]>
Wed, 1 May 2024 09:50:05 +0000 (11:50 +0200)
committerAlvaro Herrera <[email protected]>
Wed, 1 May 2024 09:50:05 +0000 (11:50 +0200)
When testing pg_upgrade against an old server, ignore failures on the
check to upgrade invalid databases.  This is necessary because old
servers don't know to raise the appropriate error of the database being
invalid.

This change causes no reduction in coverage, because such old versions
don't know to mark databases invalid when a drop is interrupted; but
testing against such old servers is useful in some circumstances.

Backpatch to 16, where it cherry-picks with minimal conflicts.

On 16, perltidy 20230309 chooses to change an unrelated line.  I let it
do that because that's the version we document as preferred for that
branch, even though it would make other changes to many other files in
the tree.

Discussion: https://postgr.es/m/202404181539[email protected]

src/bin/pg_upgrade/t/002_pg_upgrade.pl

index e5f57e550afdb2db7230625d2a3379bfa93fdab3..d1b44adb8a22e98c7a76aaf9acb3168ed2da198b 100644 (file)
@@ -318,7 +318,8 @@ if (defined($ENV{oldinstall}))
 }
 
 # Create an invalid database, will be deleted below
-$oldnode->safe_psql('postgres', qq(
+$oldnode->safe_psql(
+   'postgres', qq(
   CREATE DATABASE regression_invalid;
   UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid';
 ));
@@ -352,19 +353,31 @@ ok(-d $newnode->data_dir . "/pg_upgrade_output.d",
 rmtree($newnode->data_dir . "/pg_upgrade_output.d");
 
 # Check that pg_upgrade aborts when encountering an invalid database
-command_checks_all(
-   [
-       'pg_upgrade', '--no-sync', '-d', $oldnode->data_dir,
-       '-D', $newnode->data_dir, '-b', $oldbindir,
-       '-B', $newbindir, '-s', $newnode->host,
-       '-p', $oldnode->port, '-P', $newnode->port,
-       $mode, '--check',
-   ],
-   1,
-   [qr/invalid/], # pg_upgrade prints errors on stdout :(
-   [qr//],
-   'invalid database causes failure');
-rmtree($newnode->data_dir . "/pg_upgrade_output.d");
+# (However, versions that were out of support by commit c66a7d75e652 don't
+# know how to do this, so skip this test there.)
+SKIP:
+{
+   skip "database invalidation not implemented", 1
+     if $oldnode->pg_version < 11;
+
+   command_checks_all(
+       [
+           'pg_upgrade', '--no-sync',
+           '-d', $oldnode->data_dir,
+           '-D', $newnode->data_dir,
+           '-b', $oldbindir,
+           '-B', $newbindir,
+           '-s', $newnode->host,
+           '-p', $oldnode->port,
+           '-P', $newnode->port,
+           $mode, '--check',
+       ],
+       1,
+       [qr/invalid/],    # pg_upgrade prints errors on stdout :(
+       [qr/^$/],
+       'invalid database causes failure');
+   rmtree($newnode->data_dir . "/pg_upgrade_output.d");
+}
 
 # And drop it, so we can continue
 $oldnode->start;