Skip to content

Commit c4f7b28

Browse files
HUUTFJCommitfest Bot
authored and
Commitfest Bot
committed
Add testcase
1 parent 1e71c4d commit c4f7b28

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

src/test/subscription/t/007_ddl.pl

+81
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,87 @@
6969
"Alter subscription set publication throws warning for non-existent publication"
7070
);
7171

72+
# Cleanup
73+
$node_publisher->safe_psql('postgres', "DROP PUBLICATION mypub;");
74+
$node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION mysub1");
75+
76+
#
77+
# Test ALTER PUBLICATION RENAME command during the replication
78+
#
79+
80+
pass "renaming publications can work";
81+
82+
# Test function for swaping name of publications
83+
sub test_swap
84+
{
85+
my ($table_name, $pubname, $appname) = @_;
86+
87+
# Confirms tuples can be replicated
88+
$node_publisher->safe_psql('postgres', "INSERT INTO $table_name VALUES (1);");
89+
$node_publisher->wait_for_catchup($appname);
90+
my $result =
91+
$node_subscriber->safe_psql('postgres', "SELECT a FROM $table_name");
92+
is($result, qq(1), 'check replication worked well');
93+
94+
# Swap the name of publications; $pubname <-> pub_empty
95+
$node_publisher->safe_psql('postgres', qq[
96+
ALTER PUBLICATION $pubname RENAME TO tap_pub_tmp;
97+
ALTER PUBLICATION pub_empty RENAME TO $pubname;
98+
ALTER PUBLICATION tap_pub_tmp RENAME TO pub_empty;
99+
]);
100+
101+
# Insert the data again
102+
$node_publisher->safe_psql('postgres', "INSERT INTO $table_name VALUES (2);");
103+
$node_publisher->wait_for_catchup($appname);
104+
105+
# Confirms the second tuple won't be replicated because $pubname does not
106+
# contains relations anymore.
107+
$result =
108+
$node_subscriber->safe_psql('postgres', "SELECT a FROM $table_name ORDER BY a");
109+
is($result, qq(1),
110+
'check the tuple inserted after the RENAME was not replicated');
111+
112+
# Swap the name of publications again
113+
$node_publisher->safe_psql('postgres', qq[
114+
ALTER PUBLICATION $pubname RENAME TO tap_pub_tmp;
115+
ALTER PUBLICATION pub_empty RENAME TO $pubname;
116+
ALTER PUBLICATION tap_pub_tmp RENAME TO pub_empty;
117+
]);
118+
119+
# Confirms the replication is now resumed
120+
$node_publisher->safe_psql('postgres', "INSERT INTO $table_name VALUES (3);");
121+
$result =
122+
$node_subscriber->safe_psql('postgres', "SELECT a FROM $table_name ORDER BY a");
123+
is($result, qq(1
124+
3), 'check replicated resumed after renaming gain');
125+
}
126+
127+
# Create another table
128+
$ddl = "CREATE TABLE test2 (a int, b text);";
129+
$node_publisher->safe_psql('postgres', $ddl);
130+
$node_subscriber->safe_psql('postgres', $ddl);
131+
132+
# Create publications and a subscription
133+
$node_publisher->safe_psql('postgres', qq[
134+
CREATE PUBLICATION pub_empty;
135+
CREATE PUBLICATION pub_for_tab FOR TABLE test1;
136+
CREATE PUBLICATION pub_for_all_tables FOR ALL TABLES;
137+
]);
138+
$node_subscriber->safe_psql('postgres',
139+
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION pub_for_tab WITH (copy_data = off)"
140+
);
141+
142+
# Confirms RENAME command works well for a publication
143+
test_swap('test1', 'pub_for_tab', 'tap_sub');
144+
145+
# Switches a publication which includes all tables
146+
$node_subscriber->safe_psql('postgres',
147+
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION pub_for_all_tables WITH (refresh = true, copy_data = false);"
148+
);
149+
150+
# Confirms RENAME command works well for ALL TABLES publication
151+
test_swap('test2', 'pub_for_all_tables', 'tap_sub');
152+
72153
$node_subscriber->stop;
73154
$node_publisher->stop;
74155

0 commit comments

Comments
 (0)