Hi Peter,

On 3/23/18 10:36 AM, Peter Eisentraut wrote:
> I have committed a basic pg_resetwal test suite as part of another
> patch, so please adjust accordingly.
> 
> It looks to me like your pg_resetwal tests contain a bit of useless
> copy-and-paste.  For example, you are not using use Config, nor
> $tempdir, and you run $node->stop right after $node->start.  Please
> clean that up a bit, or comment, if appropriate.

Yeah, definitely too much copy-paste going on.

The various start/stops were intended the ensure that PG actually starts
with the reset WAL.  I see that these tests don't do them, though, so
perhaps that's not a good use of test time.

The pg_rewind tests work for my purposes but it seems worth preserving
the ones I wrote since there is no overlap.

I've attached a patch that integrates my tests with the current tests.
If you don't think they are worth adding then I'll just drop them from
my patchset.

Thanks,
-- 
-David
da...@pgmasters.net
diff --git a/src/bin/pg_resetwal/t/001_basic.pl 
b/src/bin/pg_resetwal/t/001_basic.pl
index 1b157cb555..474ece99c7 100644
--- a/src/bin/pg_resetwal/t/001_basic.pl
+++ b/src/bin/pg_resetwal/t/001_basic.pl
@@ -3,7 +3,7 @@ use warnings;
 
 use PostgresNode;
 use TestLib;
-use Test::More tests => 11;
+use Test::More tests => 16;
 
 program_help_ok('pg_resetwal');
 program_version_ok('pg_resetwal');
@@ -15,3 +15,29 @@ $node->init;
 command_like([ 'pg_resetwal', '-n', $node->data_dir ],
                         qr/checkpoint/,
                         'pg_resetwal -n produces output');
+
+# Reset WAL after segment has been removed
+my $pgwal = $node->data_dir . '/pg_wal';
+
+unlink("$pgwal/000000010000000000000001") == 1
+       or BAIL_OUT("unable to remove 000000010000000000000001");
+
+is_deeply(
+       [sort(slurp_dir($pgwal))], [sort(qw(. .. archive_status))], 'no WAL');
+
+$node->command_ok(['pg_resetwal', '-D', $node->data_dir], 'recreate pg_wal');
+
+is_deeply(
+       [sort(slurp_dir($pgwal))],
+       [sort(qw(. .. archive_status 000000010000000000000002))],
+       'WAL recreated');
+
+# Reset to specific WAL segment
+$node->command_ok(
+       ['pg_resetwal', '-l', '000000070000000700000007', '-D', 
$node->data_dir],
+       'set to specific WAL');
+
+is_deeply(
+       [sort(slurp_dir($pgwal))],
+       [sort(qw(. .. archive_status 000000070000000700000007))],
+       'WAL recreated');

Reply via email to