Skip to content

Commit 0a442a4

Browse files
author
Amit Kapila
committed
Fix 020_messages.pl test.
We were not waiting for a publisher to catch up with the subscriber after creating a subscription. Now, it can happen that apply worker starts replication even after we have disabled the subscription in the test. This will make the test expect that there is no active slot whereas there exists one. Fix this symptom by allowing the publisher to wait for catching up with the subscription. It is not a good idea to ensure if the slot is still active by checking for walsender existence as we release the slot after we clean up the walsender related memory. Fix that by checking the slot status in pg_replication_slots. Also, it is better to avoid repeated enabling/disabling of the subscription. Finally, we make autovacuum off for this test to avoid any empty transaction appearing in the test while consuming changes. Reported-by: as per buildfarm Author: Vignesh C Reviewed-by: Amit Kapila, Michael Paquier Discussion: https://postgr.es/m/CAA4eK1+uW1UGDHDz-HWMHMen76mKP7NJebOTZN4uwbyMjaYVww@mail.gmail.com
1 parent 6a5bde7 commit 0a442a4

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src/test/subscription/t/020_messages.pl

+8-23
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# Create publisher node
1212
my $node_publisher = get_new_node('publisher');
1313
$node_publisher->init(allows_streaming => 'logical');
14+
$node_publisher->append_conf('postgresql.conf',
15+
'autovacuum = off');
1416
$node_publisher->start;
1517

1618
# Create subscriber node
@@ -35,12 +37,14 @@
3537
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
3638
);
3739

40+
$node_publisher->wait_for_catchup('tap_sub');
41+
3842
# Ensure a transactional logical decoding message shows up on the slot
3943
$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE");
4044

41-
# wait for the replication connection to drop from the publisher
45+
# wait for the replication slot to become inactive in the publisher
4246
$node_publisher->poll_query_until('postgres',
43-
'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0);
47+
"SELECT COUNT(*) FROM pg_catalog.pg_replication_slots WHERE slot_name = 'tap_sub' AND active='f'", 1);
4448

4549
$node_publisher->safe_psql('postgres',
4650
"SELECT pg_logical_emit_message(true, 'pgoutput', 'a transactional message')"
@@ -77,7 +81,7 @@
7781
$result = $node_publisher->safe_psql(
7882
'postgres', qq(
7983
SELECT get_byte(data, 0)
80-
FROM pg_logical_slot_peek_binary_changes('tap_sub', NULL, NULL,
84+
FROM pg_logical_slot_get_binary_changes('tap_sub', NULL, NULL,
8185
'proto_version', '1',
8286
'publication_names', 'tap_pub')
8387
));
@@ -88,16 +92,6 @@
8892
'option messages defaults to false so message (M) is not available on slot'
8993
);
9094

91-
$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub ENABLE");
92-
$node_publisher->wait_for_catchup('tap_sub');
93-
94-
# ensure a non-transactional logical decoding message shows up on the slot
95-
$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE");
96-
97-
# wait for the replication connection to drop from the publisher
98-
$node_publisher->poll_query_until('postgres',
99-
'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0);
100-
10195
$node_publisher->safe_psql('postgres', "INSERT INTO tab_test VALUES (1)");
10296

10397
my $message_lsn = $node_publisher->safe_psql('postgres',
@@ -109,7 +103,7 @@
109103
$result = $node_publisher->safe_psql(
110104
'postgres', qq(
111105
SELECT get_byte(data, 0), get_byte(data, 1)
112-
FROM pg_logical_slot_peek_binary_changes('tap_sub', NULL, NULL,
106+
FROM pg_logical_slot_get_binary_changes('tap_sub', NULL, NULL,
113107
'proto_version', '1',
114108
'publication_names', 'tap_pub',
115109
'messages', 'true')
@@ -118,15 +112,6 @@
118112

119113
is($result, qq(77|0), 'non-transactional message on slot is M');
120114

121-
$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub ENABLE");
122-
$node_publisher->wait_for_catchup('tap_sub');
123-
124-
$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE");
125-
126-
# wait for the replication connection to drop from the publisher
127-
$node_publisher->poll_query_until('postgres',
128-
'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0);
129-
130115
# Ensure a non-transactional logical decoding message shows up on the slot when
131116
# it is emitted within an aborted transaction. The message won't emit until
132117
# something advances the LSN, hence, we intentionally forces the server to

0 commit comments

Comments
 (0)