On Fri, Jul 29, 2022 at 8:02 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > Personally I'd try to replace the two horizon-collection steps with > $newnode->psql calls, using extra_params to inject the '-o' and target > filename command line words. But if you want to try adding -X as > a quicker answer, maybe that will be enough.
Here's a patch that uses a variant of that approach: it just runs safe_psql straight up and gets the output, then writes it out to temp files if the output doesn't match and we need to run diff. Let me know what you think of this. While working on this, I noticed a few other problems. One is that the query doesn't have an ORDER BY clause, which it really should, or the output won't be stable. And the other is that I think we should be testing against the regression database, not the postgres database, because it's got a bunch of user tables in it, not just pg_largeobject. -- Robert Haas EDB: http://www.enterprisedb.com
diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl index 09af8157d0..a8df6440a4 100644 --- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl +++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl @@ -173,14 +173,10 @@ WHERE n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade', 'pg_toast')) OR (n.nspname = 'pg_catalog' AND relname IN ('pg_largeobject'))) +ORDER BY c.oid::regclass::text EOM $horizon_query =~ s/\s+/ /g; # run it together on one line -$newnode->command_ok( - [ - 'psql', '-At', '-d', $oldnode->connstr('postgres'), - '-o', "$tempdir/horizon1.txt", '-c', $horizon_query, - ], - 'horizons before running pg_upgrade'); +my $horizon1 = $oldnode->safe_psql('regression', $horizon_query); # After dumping, update references to the old source tree's regress.so # to point to the new tree. @@ -316,12 +312,7 @@ $newnode->command_ok( 'dump after running pg_upgrade'); # And second record of horizons as well. -$newnode->command_ok( - [ - 'psql', '-At', '-d', $newnode->connstr('postgres'), - '-o', "$tempdir/horizon2.txt", '-c', $horizon_query, - ], - 'horizons after running pg_upgrade'); +my $horizon2 = $newnode->safe_psql('regression', $horizon_query); # Compare the two dumps, there should be no differences. my $compare_res = compare("$tempdir/dump1.sql", "$tempdir/dump2.sql"); @@ -341,14 +332,21 @@ if ($compare_res != 0) } # Compare the horizons, there should be no differences. -$compare_res = compare("$tempdir/horizon1.txt", "$tempdir/horizon2.txt"); -is($compare_res, 0, 'old and new horizons match after pg_upgrade'); +my $horizons_ok = $horizon1 eq $horizon2; +ok($horizons_ok, 'old and new horizons match after pg_upgrade'); # Provide more context if the horizons do not match. -if ($compare_res != 0) +if (! $horizons_ok) { + # output is long, so use diff to compare + open my $fh, ">", "$tempdir/horizon1.txt" or die "could not open file: $!"; + print $fh $horizon1; + close $fh; + open $fh, ">", "$tempdir/horizon2.txt" or die "could not open file: $!"; + print $fh $horizon2; my ($stdout, $stderr) = - run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]); + run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]); + close $fh; print "=== diff of $tempdir/horizon1.txt and $tempdir/horizon2.txt\n"; print "=== stdout ===\n"; print $stdout;