postgres.git / summary / log / commit / refs

commit    0a442a408b40d2c6710de7e5397cb2e769d8c630
Author:   Amit Kapila <akapila@postgresql.org>
Date:     Wed May 19 03:24:46 2021 +0000
First released in: 14.0

    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


src/test/subscription/t/020_messages.pl | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/test/subscription/t/020_messages.pl b/src/test/subscription/t/020_messages.pl index 0940d0f45f2..52bd92df1dd 100644 --- a/src/test/subscription/t/020_messages.pl +++ b/src/test/subscription/t/020_messages.pl @@ -11,6 +11,8 @@ use Test::More tests => 5; # Create publisher node my $node_publisher = get_new_node('publisher'); $node_publisher->init(allows_streaming => 'logical'); +$node_publisher->append_conf('postgresql.conf', + 'autovacuum = off'); $node_publisher->start; # Create subscriber node @@ -35,12 +37,14 @@ $node_subscriber->safe_psql('postgres', "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub" ); +$node_publisher->wait_for_catchup('tap_sub'); + # Ensure a transactional logical decoding message shows up on the slot $node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE"); -# wait for the replication connection to drop from the publisher +# wait for the replication slot to become inactive in the publisher $node_publisher->poll_query_until('postgres', - 'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0); + "SELECT COUNT(*) FROM pg_catalog.pg_replication_slots WHERE slot_name = 'tap_sub' AND active='f'", 1); $node_publisher->safe_psql('postgres', "SELECT pg_logical_emit_message(true, 'pgoutput', 'a transactional message')" @@ -77,7 +81,7 @@ is($result, qq(1|pgoutput), $result = $node_publisher->safe_psql( 'postgres', qq( SELECT get_byte(data, 0) - FROM pg_logical_slot_peek_binary_changes('tap_sub', NULL, NULL, + FROM pg_logical_slot_get_binary_changes('tap_sub', NULL, NULL, 'proto_version', '1', 'publication_names', 'tap_pub') )); @@ -88,16 +92,6 @@ is( $result, qq(66 'option messages defaults to false so message (M) is not available on slot' ); -$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub ENABLE"); -$node_publisher->wait_for_catchup('tap_sub'); - -# ensure a non-transactional logical decoding message shows up on the slot -$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE"); - -# wait for the replication connection to drop from the publisher -$node_publisher->poll_query_until('postgres', - 'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0); - $node_publisher->safe_psql('postgres', "INSERT INTO tab_test VALUES (1)"); my $message_lsn = $node_publisher->safe_psql('postgres', @@ -109,7 +103,7 @@ $node_publisher->safe_psql('postgres', "INSERT INTO tab_test VALUES (2)"); $result = $node_publisher->safe_psql( 'postgres', qq( SELECT get_byte(data, 0), get_byte(data, 1) - FROM pg_logical_slot_peek_binary_changes('tap_sub', NULL, NULL, + FROM pg_logical_slot_get_binary_changes('tap_sub', NULL, NULL, 'proto_version', '1', 'publication_names', 'tap_pub', 'messages', 'true') @@ -118,15 +112,6 @@ $result = $node_publisher->safe_psql( is($result, qq(77|0), 'non-transactional message on slot is M'); -$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub ENABLE"); -$node_publisher->wait_for_catchup('tap_sub'); - -$node_subscriber->safe_psql('postgres', "ALTER SUBSCRIPTION tap_sub DISABLE"); - -# wait for the replication connection to drop from the publisher -$node_publisher->poll_query_until('postgres', - 'SELECT COUNT(*) FROM pg_catalog.pg_stat_replication', 0); - # Ensure a non-transactional logical decoding message shows up on the slot when # it is emitted within an aborted transaction. The message won't emit until # something advances the LSN, hence, we intentionally forces the server to [parent: 6a5bde7d4f96]