On Tue, Mar 18, 2025 at 10:12:51AM -0400, Andres Freund wrote: > On 2025-03-18 10:04:41 -0400, Tom Lane wrote: >> Robert Haas <robertmh...@gmail.com> writes: >> > I'm not quite sure what the best thing is to do is for the pg_upgrade >> > tests in particular, and it may well be best to do as you propose for >> > now and figure that out later. But I question whether just rerunning >> > all of those tests with several different mode flags is the right >> > thing to do. Why for example does 005_char_signedness.pl need to be >> > checked under both --link and --clone? I would guess that there are >> > one or maybe two tests in src/bin/pg_upgrade/t that needs to test >> > --link and --clone and they should grow internal loops to do that >> > (when supported by the local platform) and PG_UPGRADE_TEST_MODE should >> > go in the garbage. >> >> +1 >> >> I'd be particularly allergic to running 002_pg_upgrade.pl multiple >> times, as that's one of our most expensive tests, and I flat out >> don't believe that expending that many cycles could be justified. >> Surely we can test these modes sufficiently in some much cheaper and >> more targeted way. > > +1
Here is a first sketch at a test that cycles through all the transfer modes and makes sure they succeed or fail with an error along the lines of "not supported on this platform." Each test verifies that some very simple objects make it to the new version, which we could of course expand on. Would something like this suffice? -- nathan
>From 89b27b68194c2be0e1aebdee871e556028cdd5b5 Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nat...@postgresql.org> Date: Tue, 18 Mar 2025 12:21:03 -0500 Subject: [PATCH 1/1] Add test for pg_upgrade file transfer modes. --- src/bin/pg_upgrade/meson.build | 1 + src/bin/pg_upgrade/t/006_modes.pl | 63 ++++++++++++++++++++++++ src/test/perl/PostgreSQL/Test/Cluster.pm | 19 +++++++ src/test/perl/PostgreSQL/Test/Utils.pm | 25 ++++++++++ 4 files changed, 108 insertions(+) create mode 100644 src/bin/pg_upgrade/t/006_modes.pl diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index da84344966a..16cd9247e76 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -46,6 +46,7 @@ tests += { 't/003_logical_slots.pl', 't/004_subscription.pl', 't/005_char_signedness.pl', + 't/006_modes.pl', ], 'test_kwargs': {'priority': 40}, # pg_upgrade tests are slow }, diff --git a/src/bin/pg_upgrade/t/006_modes.pl b/src/bin/pg_upgrade/t/006_modes.pl new file mode 100644 index 00000000000..77ddf042ce0 --- /dev/null +++ b/src/bin/pg_upgrade/t/006_modes.pl @@ -0,0 +1,63 @@ +# Copyright (c) 2025, PostgreSQL Global Development Group + +# Tests for file transfer modes + +use strict; +use warnings FATAL => 'all'; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +sub test_mode +{ + my ($mode) = @_; + + my $old = PostgreSQL::Test::Cluster->new('old'); + my $new = PostgreSQL::Test::Cluster->new('new'); + + $old->init(); + $new->init(); + + $old->start; + $old->safe_psql('postgres', "CREATE TABLE test AS SELECT generate_series(1, 100)"); + $old->safe_psql('postgres', "CREATE DATABASE test"); + $old->safe_psql('test', "CREATE SEQUENCE test START 5432"); + $old->stop; + + my $result = command_ok_or_fails_like( + [ + 'pg_upgrade', '--no-sync', + '--old-datadir' => $old->data_dir, + '--new-datadir' => $new->data_dir, + '--old-bindir' => $old->config_data('--bindir'), + '--new-bindir' => $new->config_data('--bindir'), + '--socketdir' => $new->host, + '--old-port' => $old->port, + '--new-port' => $new->port, + $mode + ], + qr/.* not supported on this platform/, + qr/^$/, + "pg_upgrade with transfer mode $mode"); + + if ($result) + { + $new->start; + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test"); + is($result, '100', "table data after pg_upgrade $mode"); + $result = $new->safe_psql('test', "SELECT nextval('test')"); + is($result, '5432', "sequence data after pg_upgrade $mode"); + $new->stop; + } + + $old->clean_node(); + $new->clean_node(); +} + +test_mode('--clone'); +test_mode('--copy'); +test_mode('--copy-file-range'); +test_mode('--link'); + +done_testing(); diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index bab3f3d2dbe..bda19bbcee2 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -2801,6 +2801,25 @@ sub command_fails_like =pod +=item $node->command_ok_or_fails_like(...) + +PostgreSQL::Test::Utils::command_ok_or_fails_like with our connection parameters. See command_ok(...) + +=cut + +sub command_ok_or_fails_like +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my $self = shift; + + local %ENV = $self->_get_env(); + + return PostgreSQL::Test::Utils::command_ok_or_fails_like(@_); +} + +=pod + =item $node->command_checks_all(...) PostgreSQL::Test::Utils::command_checks_all with our connection parameters. See diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm index d1ad131eadf..7d7ca83495f 100644 --- a/src/test/perl/PostgreSQL/Test/Utils.pm +++ b/src/test/perl/PostgreSQL/Test/Utils.pm @@ -89,6 +89,7 @@ our @EXPORT = qw( command_like command_like_safe command_fails_like + command_ok_or_fails_like command_checks_all $windows_os @@ -1067,6 +1068,30 @@ sub command_fails_like =pod +=item command_ok_or_fails_like(cmd, expected_stdout, expected_stderr, test_name) + +Check that the command either succeeds or fails with an error that matches the +given regular expressions. + +=cut + +sub command_ok_or_fails_like +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($cmd, $expected_stdout, $expected_stderr, $test_name) = @_; + my ($stdout, $stderr); + print("# Running: " . join(" ", @{$cmd}) . "\n"); + my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr; + if (!$result) + { + like($stdout, $expected_stdout, "$test_name: stdout matches"); + like($stderr, $expected_stderr, "$test_name: stderr matches"); + } + return $result; +} + +=pod + =item command_checks_all(cmd, ret, out, err, test_name) Run a command and check its status and outputs. -- 2.39.5 (Apple Git-154)