Hi,

On 3/1/18 11:59 PM, Michael Paquier wrote:
> On Thu, Mar 01, 2018 at 01:12:19PM -0500, David Steele wrote:
>> But your point is well-taken.  No symlinks are used in this test so it
>> *should* work.
>>
>> Michael, what do you think?
> 
> Perl's symlink() does not work on Windows.  It does not fly higher than
> that, and that's the reason why a good chunk of the tests are skipped
> for pg_basebackup.  If perl was to have a version of symlink() which
> works, say with junction points, or if Windows was to have a sane
> symlink implementation (or with [1]?), or if it was possible to create
> junction points using an in-core implementation in perl, then those
> tests could not be skipped. But it seems that none of those scenarios
> have happened yet.
> 
> From what I read in your patch, it seems to me that this test should
> work.  If they don't for whatever reason, your patch then does not give
> a correct justification explaining why they should be skipped.

Thanks for the input, Michael.

Attached is a new version that does not skip tests on Windows.  I don't
have any way to test it, but if one of you do that would be much
appreciated.

Thanks!
-- 
-David
da...@pgmasters.net
From 04550fb532dc4d3894a92d397f6303fddcaf75b2 Mon Sep 17 00:00:00 2001
From: David Steele <da...@pgmasters.net>
Date: Mon, 5 Mar 2018 12:21:53 -0500
Subject: [PATCH 1/1] Reinit.c regression tests.

Add regression tests for reinit.c.

These were originally written for a patch that refactored reinit.c.  That 
refactor ended up not being needed, but it seems like a good idea to add the 
tests.
---
 src/test/recovery/t/014_unlogged_reinit.pl | 96 ++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 src/test/recovery/t/014_unlogged_reinit.pl

diff --git a/src/test/recovery/t/014_unlogged_reinit.pl 
b/src/test/recovery/t/014_unlogged_reinit.pl
new file mode 100644
index 0000000000..290196291f
--- /dev/null
+++ b/src/test/recovery/t/014_unlogged_reinit.pl
@@ -0,0 +1,96 @@
+# Tests that unlogged tables are properly reinitialized after a crash.
+#
+# The behavior should be the same when restoring from a backup but that is not
+# tested here (yet).
+use strict;
+use warnings;
+use PostgresNode;
+use TestLib;
+use Test::More tests => 16;
+
+# Initialize node without replication settings
+my $node = get_new_node('main');
+
+$node->init;
+$node->start;
+my $pgdata = $node->data_dir;
+
+# Create an unlogged table to test that forks other than init are not copied
+$node->safe_psql('postgres', 'CREATE UNLOGGED TABLE base_unlogged (id int)');
+
+my $baseUnloggedPath = $node->safe_psql('postgres',
+       q{select pg_relation_filepath('base_unlogged')});
+
+# Make sure main and init forks exist
+ok(-f "$pgdata/${baseUnloggedPath}_init", 'init fork in base');
+ok(-f "$pgdata/$baseUnloggedPath", 'main fork in base');
+
+# Create unlogged tables in a tablespace
+my $tablespaceDir = undef;
+my $ts1UnloggedPath = undef;
+
+$tablespaceDir = TestLib::tempdir . "/ts1";
+
+mkdir($tablespaceDir)
+       or die "unable to mkdir \"$tablespaceDir\"";
+
+$node->safe_psql('postgres',
+       "CREATE TABLESPACE ts1 LOCATION '$tablespaceDir'");
+$node->safe_psql('postgres',
+       'CREATE UNLOGGED TABLE ts1_unlogged (id int) TABLESPACE ts1');
+
+       $ts1UnloggedPath = $node->safe_psql('postgres',
+       q{select pg_relation_filepath('ts1_unlogged')});
+
+# Make sure main and init forks exist
+ok(-f "$pgdata/${ts1UnloggedPath}_init", 'init fork in tablespace');
+ok(-f "$pgdata/$ts1UnloggedPath", 'main fork in tablespace');
+
+# Crash the postmaster
+$node->stop('immediate');
+
+# Write forks to test that they are removed during recovery
+$node->command_ok(['touch', "$pgdata/${baseUnloggedPath}_vm"],
+       'touch vm fork in base');
+$node->command_ok(['touch', "$pgdata/${baseUnloggedPath}_fsm"],
+       'touch fsm fork in base');
+
+# Remove main fork to test that it is recopied from init
+unlink("$pgdata/${baseUnloggedPath}")
+       or die "unable to remove \"${baseUnloggedPath}\"";
+
+# Write forks to test that they are removed by recovery
+$node->command_ok(['touch', "$pgdata/${ts1UnloggedPath}_vm"],
+       'touch vm fork in tablespace');
+$node->command_ok(['touch', "$pgdata/${ts1UnloggedPath}_fsm"],
+       'touch fsm fork in tablespace');
+
+# Remove main fork to test that it is recopied from init
+unlink("$pgdata/${ts1UnloggedPath}")
+       or die "unable to remove \"${ts1UnloggedPath}\"";
+
+# Start the postmaster
+$node->start;
+
+# Check unlogged table in base
+ok(-f "$pgdata/${baseUnloggedPath}_init", 'init fork in base');
+ok(-f "$pgdata/$baseUnloggedPath", 'main fork in base');
+ok(!-f "$pgdata/${baseUnloggedPath}_vm", 'vm fork not in base');
+ok(!-f "$pgdata/${baseUnloggedPath}_fsm", 'fsm fork not in base');
+
+# Drop unlogged table
+$node->safe_psql('postgres', 'DROP TABLE base_unlogged');
+
+# Check unlogged table in tablespace
+ok(-f "$pgdata/${ts1UnloggedPath}_init", 'init fork in tablespace');
+ok(-f "$pgdata/$ts1UnloggedPath", 'main fork in tablespace');
+ok(!-f "$pgdata/${ts1UnloggedPath}_vm", 'vm fork not in tablespace');
+ok(!-f "$pgdata/${ts1UnloggedPath}_fsm", 'fsm fork not in tablespace');
+
+# Drop unlogged table
+$node->safe_psql('postgres', 'DROP TABLE ts1_unlogged');
+
+# Drop tablespace
+$node->safe_psql('postgres', 'DROP TABLESPACE ts1');
+rmdir($tablespaceDir)
+       or die "unable to rmdir \"$tablespaceDir\"";
-- 
2.14.3 (Apple Git-98)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to