From eef34447d9b69c32cd6da5116f24cd628370d4a9 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Tue, 8 Mar 2016 14:34:36 +0800
Subject: [PATCH 2/7] Update decoding_failover tests for failover slots

---
 .../recovery/t/006_logical_decoding_timelines.pl   | 29 +++++++++-------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/test/recovery/t/006_logical_decoding_timelines.pl b/src/test/recovery/t/006_logical_decoding_timelines.pl
index 1372d90..ed6cac7 100644
--- a/src/test/recovery/t/006_logical_decoding_timelines.pl
+++ b/src/test/recovery/t/006_logical_decoding_timelines.pl
@@ -19,7 +19,7 @@ use strict;
 use warnings;
 use PostgresNode;
 use TestLib;
-use Test::More tests => 20;
+use Test::More tests => 19;
 use RecursiveCopy;
 use File::Copy;
 
@@ -64,7 +64,7 @@ $node_master->safe_psql('postgres', 'CHECKPOINT;');
 
 # Verify that only the before base_backup slot is on the replica
 $stdout = $node_replica->safe_psql('postgres', 'SELECT slot_name FROM pg_replication_slots ORDER BY slot_name');
-is($stdout, 'before_basebackup', 'Expected to find only slot before_basebackup on replica');
+is($stdout, '', 'Expected to find no slots on replica');
 
 # Boom, crash
 $node_master->stop('immediate');
@@ -86,22 +86,16 @@ like(
 	qr/replication slot "after_basebackup" does not exist/,
 	'after_basebackup slot missing');
 
-# Should be able to read from slot created before base backup
+# or before_basebackup, since pg_basebackup dropped it
 ($ret, $stdout, $stderr) = $node_replica->psql(
 	'postgres',
 "SELECT data FROM pg_logical_slot_peek_changes('before_basebackup', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');",
 	timeout => 30);
-is($ret, 0, 'replay from slot before_basebackup succeeds');
-is( $stdout, q(BEGIN
-table public.decoding: INSERT: blah[text]:'beforebb'
-COMMIT
-BEGIN
-table public.decoding: INSERT: blah[text]:'afterbb'
-COMMIT
-BEGIN
-table public.decoding: INSERT: blah[text]:'after failover'
-COMMIT), 'decoded expected data from slot before_basebackup');
-is($stderr, '', 'replay from slot before_basebackup produces no stderr');
+is($ret, 3, 'replaying from beforebasebackup slot fails');
+like(
+	$stderr,
+	qr/replication slot "before_basebackup" does not exist/,
+	'before_basebackup slot missing');
 
 # We don't need the standby anymore
 $node_replica->teardown_node();
@@ -121,9 +115,10 @@ is($node_master->psql('postgres', 'SELECT pg_drop_replication_slot(slot_name) FR
   0, 'dropping slots succeeds via pg_drop_replication_slot');
 
 # Same as before, we'll make one slot before basebackup, one after. This time
-# the basebackup will be with pg_basebackup so it'll omit both slots, then
-# we'll use SQL functions provided by the decoding_failover test module to
-# sync them to the replica, do some work, sync them and fail over then test
+# the basebackup will be with pg_basebackup. It'll copy the before_basebackup slot
+# but since it's a non-failover slot the server will drop it immediately.
+# We'll use SQL functions provided by the decoding_failover test module to
+# sync both slots to the replica, do some work, sync them and fail over then test
 # again. This time we should have both the before- and after-basebackup
 # slots working.
 
-- 
2.1.0

