Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit036642a

Browse files
author
Amit Kapila
committed
Back-Patch "Add wait_for_subscription_sync for TAP tests."
This was originally done in commit0c20dd3 for 16 only, to eliminateduplicate code and as an infrastructure that makes it easier to writefuture tests. However, it has been suggested that it would be good toback-patch this testing infrastructure to aid future tests inback-branches.Backpatch to all supported versions.Author: Masahiko SawadaReviewed by: Amit Kapila, Shi yuDiscussion:https://postgr.es/m/CAD21AoC-fvAkaKHa4t1urupwL8xbAcWRePeETvshvy80f6WV1A@mail.gmail.comDiscussion:https://postgr.es/m/E1oJBIf-0006sw-SA@gemulon.postgresql.org
1 parent7944607 commit036642a

File tree

10 files changed

+65
-67
lines changed

10 files changed

+65
-67
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,50 @@ sub wait_for_slot_catchup
20862086

20872087
=pod
20882088
2089+
=item$node->wait_for_subscription_sync(publisher, subname, dbname)
2090+
2091+
Wait for all tables in pg_subscription_rel to complete the initial
2092+
synchronization (i.e to be either in 'syncdone' or 'ready' state).
2093+
2094+
If the publisher node is given, additionally, check if the subscriber has
2095+
caught up to what has been committed on the primary. This is useful to
2096+
ensure that the initial data synchronization has been completed after
2097+
creating a new subscription.
2098+
2099+
If there is no active replication connection from this peer, wait until
2100+
poll_query_until timeout.
2101+
2102+
This is not a test. It die()s on failure.
2103+
2104+
=cut
2105+
2106+
subwait_for_subscription_sync
2107+
{
2108+
my ($self,$publisher,$subname,$dbname) =@_;
2109+
my$name =$self->name;
2110+
2111+
$dbname =defined($dbname) ?$dbname :'postgres';
2112+
2113+
# Wait for all tables to finish initial sync.
2114+
print"Waiting for all subscriptions in\"$name\" to synchronize data\n";
2115+
my$query =
2116+
qq[SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');];
2117+
$self->poll_query_until($dbname,$query)
2118+
or croak"timed out waiting for subscriber to synchronize data";
2119+
2120+
# Then, wait for the replication to catchup if required.
2121+
if (defined($publisher))
2122+
{
2123+
croak'subscription name must be specified'unlessdefined($subname);
2124+
$publisher->wait_for_catchup($subname);
2125+
}
2126+
2127+
print"done\n";
2128+
return;
2129+
}
2130+
2131+
=pod
2132+
20892133
=item$node->wait_for_log(regexp, offset)
20902134
20912135
Waits for the contents of the server log file, starting at the given offset, to

‎src/test/subscription/t/001_rep_changes.pl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,8 @@
8585
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub, tap_pub_ins_only"
8686
);
8787

88-
$node_publisher->wait_for_catchup('tap_sub');
89-
90-
# Also wait for initial table sync to finish
91-
my$synced_query =
92-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
93-
$node_subscriber->poll_query_until('postgres',$synced_query)
94-
ordie"Timed out while waiting for subscriber to synchronize data";
88+
# Wait for initial table sync to finish
89+
$node_subscriber->wait_for_subscription_sync($node_publisher,'tap_sub');
9590

9691
my$result =
9792
$node_subscriber->safe_psql('postgres',"SELECT count(*) FROM tab_notrep");

‎src/test/subscription/t/002_types.pl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,8 @@
111111
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (slot_name = tap_sub_slot)"
112112
);
113113

114-
$node_publisher->wait_for_catchup('tap_sub');
115-
116-
# Wait for initial sync to finish as well
117-
my$synced_query =
118-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');";
119-
$node_subscriber->poll_query_until('postgres',$synced_query)
120-
ordie"Timed out while waiting for subscriber to synchronize data";
114+
# Wait for initial sync to finish
115+
$node_subscriber->wait_for_subscription_sync($node_publisher,'tap_sub');
121116

122117
# Insert initial test data
123118
$node_publisher->safe_psql(

‎src/test/subscription/t/004_sync.pl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@
3636
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
3737
);
3838

39-
$node_publisher->wait_for_catchup('tap_sub');
40-
41-
# Also wait for initial table sync to finish
42-
my$synced_query =
43-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
44-
$node_subscriber->poll_query_until('postgres',$synced_query)
45-
ordie"Timed out while waiting for subscriber to synchronize data";
39+
# Wait for initial table sync to finish
40+
$node_subscriber->wait_for_subscription_sync($node_publisher,'tap_sub');
4641

4742
my$result =
4843
$node_subscriber->safe_psql('postgres',"SELECT count(*) FROM tab_rep");
@@ -68,8 +63,7 @@
6863
$node_subscriber->safe_psql('postgres',"DELETE FROM tab_rep;");
6964

7065
# wait for sync to finish this time
71-
$node_subscriber->poll_query_until('postgres',$synced_query)
72-
ordie"Timed out while waiting for subscriber to synchronize data";
66+
$node_subscriber->wait_for_subscription_sync;
7367

7468
# check that all data is synced
7569
$result =
@@ -104,8 +98,7 @@
10498
);
10599

106100
# and wait for data sync to finish again
107-
$node_subscriber->poll_query_until('postgres',$synced_query)
108-
ordie"Timed out while waiting for subscriber to synchronize data";
101+
$node_subscriber->wait_for_subscription_sync;
109102

110103
# check that all data is synced
111104
$result =
@@ -130,8 +123,7 @@
130123
"ALTER SUBSCRIPTION tap_sub REFRESH PUBLICATION");
131124

132125
# wait for sync to finish
133-
$node_subscriber->poll_query_until('postgres',$synced_query)
134-
ordie"Timed out while waiting for subscriber to synchronize data";
126+
$node_subscriber->wait_for_subscription_sync;
135127

136128
$result =$node_subscriber->safe_psql('postgres',
137129
"SELECT count(*) FROM tab_rep_next");

‎src/test/subscription/t/005_encoding.pl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@
2929
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
3030
);
3131

32-
$node_publisher->wait_for_catchup('mysub');
33-
34-
# Wait for initial sync to finish as well
35-
my$synced_query =
36-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');";
37-
$node_subscriber->poll_query_until('postgres',$synced_query)
38-
ordie"Timed out while waiting for subscriber to synchronize data";
32+
# Wait for initial sync to finish
33+
$node_subscriber->wait_for_subscription_sync($node_publisher,'mysub');
3934

4035
$node_publisher->safe_psql('postgres',
4136
q{INSERT INTO test1 VALUES (1, E'Mot\xc3\xb6rhead')});# hand-rolled UTF-8

‎src/test/subscription/t/006_rewrite.pl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@
2525
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
2626
);
2727

28-
$node_publisher->wait_for_catchup('mysub');
29-
30-
# Wait for initial sync to finish as well
31-
my$synced_query =
32-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');";
33-
$node_subscriber->poll_query_until('postgres',$synced_query)
34-
ordie"Timed out while waiting for subscriber to synchronize data";
28+
# Wait for initial sync to finish
29+
$node_subscriber->wait_for_subscription_sync($node_publisher,'mysub');
3530

3631
$node_publisher->safe_psql('postgres',
3732
q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');});

‎src/test/subscription/t/008_diff_schema.pl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@
3535
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
3636
);
3737

38-
$node_publisher->wait_for_catchup('tap_sub');
39-
40-
# Also wait for initial table sync to finish
41-
my$synced_query =
42-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
43-
$node_subscriber->poll_query_until('postgres',$synced_query)
44-
ordie"Timed out while waiting for subscriber to synchronize data";
38+
# Wait for initial table sync to finish
39+
$node_subscriber->wait_for_subscription_sync($node_publisher,'tap_sub');
4540

4641
my$result =
4742
$node_subscriber->safe_psql('postgres',
@@ -104,8 +99,7 @@
10499
$node_subscriber->safe_psql('postgres',
105100
"ALTER SUBSCRIPTION tap_sub REFRESH PUBLICATION");
106101

107-
$node_subscriber->poll_query_until('postgres',$synced_query)
108-
ordie"Timed out while waiting for subscriber to synchronize data";
102+
$node_subscriber->wait_for_subscription_sync;
109103

110104
# Add replica identity column. (The serial is not necessary, but it's
111105
# a convenient way to get a default on the new column so that rows

‎src/test/subscription/t/010_truncate.pl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@
6464
);
6565

6666
# Wait for initial sync of all subscriptions
67-
my$synced_query =
68-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
69-
$node_subscriber->poll_query_until('postgres',$synced_query)
70-
ordie"Timed out while waiting for subscriber to synchronize data";
67+
$node_subscriber->wait_for_subscription_sync;
7168

7269
# insert data to truncate
7370

@@ -180,8 +177,7 @@
180177
);
181178

182179
# wait for initial data sync
183-
$node_subscriber->poll_query_until('postgres',$synced_query)
184-
ordie"Timed out while waiting for subscriber to synchronize data";
180+
$node_subscriber->wait_for_subscription_sync;
185181

186182
# insert data to truncate
187183

‎src/test/subscription/t/011_generated.pl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
);
3838

3939
# Wait for initial sync of all subscriptions
40-
my$synced_query =
41-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
42-
$node_subscriber->poll_query_until('postgres',$synced_query)
43-
ordie"Timed out while waiting for subscriber to synchronize data";
40+
$node_subscriber->wait_for_subscription_sync;
4441

4542
my$result =$node_subscriber->safe_psql('postgres',"SELECT a, b FROM tab1");
4643
is($result,qq(1|22

‎src/test/subscription/t/100_bugs.pl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,8 @@
154154
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
155155
);
156156

157-
$node_publisher->wait_for_catchup('tap_sub');
158-
159-
# Also wait for initial table sync to finish
160-
my$synced_query =
161-
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');";
162-
$node_subscriber->poll_query_until('postgres',$synced_query)
163-
ordie"Timed out while waiting for subscriber to synchronize data";
157+
# Wait for initial table sync to finish
158+
$node_subscriber->wait_for_subscription_sync($node_publisher,'tap_sub');
164159

165160
is($node_subscriber->safe_psql(
166161
'postgres',"SELECT * FROM tab_replidentity_index"),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp