|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 3; |
| 6 | +use Test::More tests => 5; |
7 | 7 |
|
8 | 8 | # Bug #15114
|
9 | 9 |
|
|
100 | 100 | );
|
101 | 101 |
|
102 | 102 | $node_publisher->stop('fast');
|
| 103 | + |
| 104 | +# Bug #16643 - https://postgr.es/m/[email protected] |
| 105 | +# |
| 106 | +# Initial sync doesn't complete; the protocol was not being followed per |
| 107 | +# expectations after commit 07082b08cc5d. |
| 108 | +my $node_twoways = get_new_node('twoways'); |
| 109 | +$node_twoways->init(allows_streaming => 'logical'); |
| 110 | +$node_twoways->start; |
| 111 | +for my $db (qw(d1 d2)) |
| 112 | +{ |
| 113 | + $node_twoways->safe_psql('postgres', "CREATE DATABASE $db"); |
| 114 | + $node_twoways->safe_psql($db, "CREATE TABLE t (f int)"); |
| 115 | + $node_twoways->safe_psql($db, "CREATE TABLE t2 (f int)"); |
| 116 | +} |
| 117 | + |
| 118 | +my $rows = 3000; |
| 119 | +$node_twoways->safe_psql( |
| 120 | + 'd1', qq{ |
| 121 | + INSERT INTO t SELECT * FROM generate_series(1, $rows); |
| 122 | + INSERT INTO t2 SELECT * FROM generate_series(1, $rows); |
| 123 | + CREATE PUBLICATION testpub FOR TABLE t; |
| 124 | + SELECT pg_create_logical_replication_slot('testslot', 'pgoutput'); |
| 125 | + }); |
| 126 | + |
| 127 | +$node_twoways->safe_psql('d2', |
| 128 | + "CREATE SUBSCRIPTION testsub CONNECTION \$\$" |
| 129 | + . $node_twoways->connstr('d1') |
| 130 | + . "\$\$ PUBLICATION testpub WITH (create_slot=false, " |
| 131 | + . "slot_name='testslot')"); |
| 132 | +$node_twoways->safe_psql( |
| 133 | + 'd1', qq{ |
| 134 | + INSERT INTO t SELECT * FROM generate_series(1, $rows); |
| 135 | + INSERT INTO t2 SELECT * FROM generate_series(1, $rows); |
| 136 | + }); |
| 137 | +$node_twoways->safe_psql( |
| 138 | + 'd1', 'ALTER PUBLICATION testpub ADD TABLE t2'); |
| 139 | +$node_twoways->safe_psql( |
| 140 | + 'd2', 'ALTER SUBSCRIPTION testsub REFRESH PUBLICATION'); |
| 141 | + |
| 142 | +# We cannot rely solely on wait_for_catchup() here; it isn't sufficient |
| 143 | +# when tablesync workers might still be running. So in addition to that, |
| 144 | +# we verify that no tablesync workers appear for the subscription. |
| 145 | +# XXX maybe this should be integrated in wait_for_catchup() itself. |
| 146 | +$node_twoways->wait_for_catchup('testsub'); |
| 147 | +$node_twoways->poll_query_until( |
| 148 | + 'd2', |
| 149 | + "SELECT count(*) FROM pg_stat_subscription WHERE subname = 'testsub' AND relid <> 0", |
| 150 | + "0"); |
| 151 | + |
| 152 | +is($node_twoways->safe_psql('d2', "SELECT count(f) FROM t"), |
| 153 | + $rows * 2, "2x$rows rows in t"); |
| 154 | +is($node_twoways->safe_psql('d2', "SELECT count(f) FROM t2"), |
| 155 | + $rows * 2, "2x$rows rows in t2"); |
0 commit comments