Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 212bdc0

Browse files
committed
Revise test case added in 4374699.
Instead of using command_ok() to run psql, use safe_psql(). wrasse isn't happy, and it be because of failure to pass -X to the psql invocation, which safe_psql() will do automatically. Since safe_psql() returns standard output instead of writing it to a file, this requires some changes to the incantation for running 'diff'. Test against the 'regression' database rather than 'postgres' so we test more than just one table. That also means we need to record the horizons later, after the test does "VACUUM FULL pg_largeobject". Add an ORDER BY clause to the horizon query for stability. Patch by me, reviewed by Tom Lane. Discussion: http://postgr.es/m/CA+TgmoaGBbpzgu3=du1f9zDUbkfycO0y=_uWrLFy=KKEqXWeLQ@mail.gmail.com
1 parent b998196 commit 212bdc0

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

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

+30-32
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,6 @@ sub generate_db
161161
],
162162
'dump before running pg_upgrade');
163163

164-
# Also record the relfrozenxid and relminmxid horizons.
165-
my $horizon_query = <<EOM;
166-
SELECT
167-
c.oid::regclass, c.relfrozenxid, c.relminmxid
168-
FROM
169-
pg_class c, pg_namespace n
170-
WHERE
171-
c.relnamespace = n.oid AND
172-
((n.nspname !~ '^pg_temp_' AND n.nspname !~ '^pg_toast_temp_' AND
173-
n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade',
174-
'pg_toast'))
175-
OR (n.nspname = 'pg_catalog' AND relname IN ('pg_largeobject')))
176-
EOM
177-
$horizon_query =~ s/\s+/ /g; # run it together on one line
178-
$newnode->command_ok(
179-
[
180-
'psql', '-At', '-d', $oldnode->connstr('postgres'),
181-
'-o', "$tempdir/horizon1.txt", '-c', $horizon_query,
182-
],
183-
'horizons before running pg_upgrade');
184-
185164
# After dumping, update references to the old source tree's regress.so
186165
# to point to the new tree.
187166
if (defined($ENV{oldinstall}))
@@ -231,6 +210,23 @@ sub generate_db
231210

232211
$oldnode->safe_psql("regression", "VACUUM FULL pg_largeobject;");
233212

213+
# Record the relfrozenxid and relminmxid horizons from the old server.
214+
my $horizon_query = <<EOM;
215+
SELECT
216+
c.oid::regclass, c.relfrozenxid, c.relminmxid
217+
FROM
218+
pg_class c, pg_namespace n
219+
WHERE
220+
c.relnamespace = n.oid AND
221+
((n.nspname !~ '^pg_temp_' AND n.nspname !~ '^pg_toast_temp_' AND
222+
n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade',
223+
'pg_toast'))
224+
OR (n.nspname = 'pg_catalog' AND relname IN ('pg_largeobject')))
225+
ORDER BY c.oid::regclass::text
226+
EOM
227+
$horizon_query =~ s/\s+/ /g; # run it together on one line
228+
my $horizon1 = $oldnode->safe_psql('regression', $horizon_query);
229+
234230
# In a VPATH build, we'll be started in the source directory, but we want
235231
# to run pg_upgrade in the build directory so that any files generated finish
236232
# in it, like delete_old_cluster.{sh,bat}.
@@ -315,13 +311,8 @@ sub generate_db
315311
],
316312
'dump after running pg_upgrade');
317313

318-
# And second record of horizons as well.
319-
$newnode->command_ok(
320-
[
321-
'psql', '-At', '-d', $newnode->connstr('postgres'),
322-
'-o', "$tempdir/horizon2.txt", '-c', $horizon_query,
323-
],
324-
'horizons after running pg_upgrade');
314+
# And record the horizons from the upgraded cluster as well.
315+
my $horizon2 = $newnode->safe_psql('regression', $horizon_query);
325316

326317
# Compare the two dumps, there should be no differences.
327318
my $compare_res = compare("$tempdir/dump1.sql", "$tempdir/dump2.sql");
@@ -341,14 +332,21 @@ sub generate_db
341332
}
342333

343334
# Compare the horizons, there should be no differences.
344-
$compare_res = compare("$tempdir/horizon1.txt", "$tempdir/horizon2.txt");
345-
is($compare_res, 0, 'old and new horizons match after pg_upgrade');
335+
my $horizons_ok = $horizon1 eq $horizon2;
336+
ok($horizons_ok, 'old and new horizons match after pg_upgrade');
346337

347338
# Provide more context if the horizons do not match.
348-
if ($compare_res != 0)
339+
if (! $horizons_ok)
349340
{
341+
# output is long, so use diff to compare
342+
open my $fh, ">", "$tempdir/horizon1.txt" or die "could not open file: $!";
343+
print $fh $horizon1;
344+
close $fh;
345+
open $fh, ">", "$tempdir/horizon2.txt" or die "could not open file: $!";
346+
print $fh $horizon2;
350347
my ($stdout, $stderr) =
351-
run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]);
348+
run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]);
349+
close $fh;
352350
print "=== diff of $tempdir/horizon1.txt and $tempdir/horizon2.txt\n";
353351
print "=== stdout ===\n";
354352
print $stdout;

0 commit comments

Comments
 (0)