From fbee24aeace55c21f291b161391b88c433258da5 Mon Sep 17 00:00:00 2001
From: Shlok Kyal <shlok.kyal.oss@gmail.com>
Date: Wed, 22 Jan 2025 20:59:17 +0530
Subject: [PATCH v6 2/2] Test for Improve logging for data origin discrepancies
 in table synchronization

---
 src/test/subscription/t/030_origin.pl | 69 +++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/src/test/subscription/t/030_origin.pl b/src/test/subscription/t/030_origin.pl
index eb1dcb7271..0ffec5a181 100644
--- a/src/test/subscription/t/030_origin.pl
+++ b/src/test/subscription/t/030_origin.pl
@@ -255,6 +255,75 @@ $node_A->safe_psql('postgres', "DROP TABLE tab_new");
 $node_B->safe_psql('postgres', "DROP TABLE tab_new");
 $node_A->safe_psql('postgres', "DROP SUBSCRIPTION $subname_AB2");
 
+###############################################################################
+# Specifying origin = NONE and copy_data = on must raise WARNING if we subscribe
+# to a partitioned table and this table contains any remotely originated data.
+###############################################################################
+
+# create a partition table on node A
+$node_A->safe_psql(
+	'postgres', qq(
+CREATE SCHEMA ts;
+CREATE TABLE ts.t(id int) PARTITION BY RANGE(id);
+CREATE TABLE ts.part1 PARTITION OF ts.t FOR VALUES FROM (0) TO (5);
+CREATE TABLE ts.part2 PARTITION OF ts.t FOR VALUES FROM (5) TO (10);
+));
+
+# create a table on node B which will act as a source for a partition on node A
+$node_B->safe_psql(
+	'postgres', qq(
+CREATE SCHEMA ts;
+CREATE TABLE ts.part2(id int);
+CREATE PUBLICATION pub_b_a FOR TABLE ts.part2;
+));
+$node_A->safe_psql('postgres',
+	"CREATE SUBSCRIPTION sub_a_b CONNECTION '$node_B_connstr' PUBLICATION pub_b_a;"
+);
+
+# create a table on node C
+$node_C->safe_psql(
+	'postgres', "
+CREATE SCHEMA ts;
+CREATE TABLE ts.t(id int);");
+
+# create a logical replication setup between node A and node C with
+# subscription on node C having origin = NONE and copy_data = on
+$node_A->safe_psql(
+	'postgres', "
+CREATE PUBLICATION pub_a_c FOR TABLE ts.t WITH (publish_via_partition_root);
+");
+
+($result, $stdout, $stderr) = $node_C->psql(
+	'postgres', "
+	CREATE SUBSCRIPTION sub_a_c CONNECTION '$node_A_connstr' PUBLICATION pub_a_c WITH (origin = none, copy_data = on);
+");
+
+# A warning must be logged as a partition of table in node A might have
+# remotely originated data
+like(
+	$stderr,
+	qr/WARNING: ( [A-Z0-9]+:)? subscription "sub_a_c" requested copy_data with origin = NONE but might copy data that had a different origin/,
+	"Create subscription with origin = none and copy_data when the publisher has subscribed a partitioned table"
+);
+
+# clear the operations done by this test
+$node_C->safe_psql(
+	'postgres', qq(
+DROP SUBSCRIPTION sub_a_c;
+DROP SCHEMA ts CASCADE;
+));
+$node_A->safe_psql(
+	'postgres', qq(
+DROP SUBSCRIPTION sub_a_b;
+DROP PUBLICATION pub_a_c;
+DROP SCHEMA ts CASCADE;
+));
+$node_B->safe_psql(
+	'postgres', qq(
+DROP PUBLICATION pub_b_a;
+DROP SCHEMA ts CASCADE;
+));
+
 # shutdown
 $node_B->stop('fast');
 $node_A->stop('fast');
-- 
2.34.1

