|
6 | 6 | use warnings;
|
7 | 7 | use PostgreSQL::Test::Cluster;
|
8 | 8 | use PostgreSQL::Test::Utils;
|
9 |
| -use Test::Moretests=>5; |
| 9 | +use Test::Moretests=>3; |
10 | 10 |
|
11 | 11 | # Test if the error reported on pg_stat_subscription_workers view is expected.
|
12 | 12 | subtest_subscription_error
|
13 | 13 | {
|
14 |
| -my ($node,$relname,$xid,$expected_error,$msg) =@_; |
| 14 | +my ($node,$relname,$command,$xid,$by_apply_worker,$errmsg_prefix,$msg) |
| 15 | +=@_; |
15 | 16 |
|
16 | 17 | my$check_sql =qq[
|
17 |
| -SELECT count(1) > 0 FROM pg_stat_subscription_workers |
18 |
| -WHERE last_error_relid = '$relname'::regclass]; |
19 |
| -$check_sql .=" AND last_error_xid = '$xid'::xid;"if$xidne''; |
20 |
| - |
21 |
| -# Wait for the error statistics to be updated. |
22 |
| -$node->poll_query_until( |
23 |
| -'postgres',$check_sql, |
24 |
| -)ordie"Timed out while waiting for statistics to be updated"; |
25 |
| - |
26 |
| -my$result =$node->safe_psql( |
27 |
| -'postgres', |
28 |
| -qq[ |
29 |
| -SELECT subname, last_error_command, last_error_relid::regclass, last_error_count > 0 |
| 18 | +SELECT count(1) > 0 |
30 | 19 | FROM pg_stat_subscription_workers
|
31 |
| -WHERE last_error_relid = '$relname'::regclass; |
32 |
| -]); |
33 |
| - is($result,$expected_error,$msg); |
| 20 | +WHERE last_error_relid = '$relname'::regclass |
| 21 | + AND starts_with(last_error_message, '$errmsg_prefix')]; |
| 22 | + |
| 23 | +# subrelid |
| 24 | +$check_sql .=$by_apply_worker |
| 25 | +?qq[ AND subrelid IS NULL] |
| 26 | +:qq[ AND subrelid = '$relname'::regclass]; |
| 27 | + |
| 28 | +# last_error_command |
| 29 | +$check_sql .=$commandeq'' |
| 30 | +?qq[ AND last_error_command IS NULL] |
| 31 | +:qq[ AND last_error_command = '$command']; |
| 32 | + |
| 33 | +# last_error_xid |
| 34 | +$check_sql .=$xideq'' |
| 35 | +?qq[ AND last_error_xid IS NULL] |
| 36 | +:qq[ AND last_error_xid = '$xid'::xid]; |
| 37 | + |
| 38 | +# Wait for the particular error statistics to be reported. |
| 39 | +$node->poll_query_until('postgres',$check_sql, |
| 40 | +)ordie"Timed out while waiting for" .$msg; |
34 | 41 | }
|
35 | 42 |
|
36 | 43 | # Create publisher node.
|
@@ -89,7 +96,7 @@ sub test_subscription_error
|
89 | 96 | # infinite error loop due to violating the unique constraint.
|
90 | 97 | $node_subscriber->safe_psql(
|
91 | 98 | 'postgres',
|
92 |
| -"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (streaming = off);"); |
| 99 | +"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub;"); |
93 | 100 |
|
94 | 101 | $node_publisher->wait_for_catchup('tap_sub');
|
95 | 102 |
|
@@ -117,14 +124,16 @@ sub test_subscription_error
|
117 | 124 | SELECT pg_current_xact_id()::xid;
|
118 | 125 | COMMIT;
|
119 | 126 | ]);
|
120 |
| -test_subscription_error($node_subscriber,'test_tab1',$xid, |
121 |
| -qq(tap_sub|INSERT|test_tab1|t), |
122 |
| -'check the error reported by the apply worker'); |
| 127 | +test_subscription_error($node_subscriber,'test_tab1','INSERT',$xid, |
| 128 | +1,# check apply worker error |
| 129 | +qq(duplicate key value violates unique constraint), |
| 130 | +'error reported by the apply worker'); |
123 | 131 |
|
124 | 132 | # Check the table sync worker's error in the view.
|
125 |
| -test_subscription_error($node_subscriber,'test_tab2','', |
126 |
| -qq(tap_sub||test_tab2|t), |
127 |
| -'check the error reported by the table sync worker'); |
| 133 | +test_subscription_error($node_subscriber,'test_tab2','','', |
| 134 | +0,# check tablesync worker error |
| 135 | +qq(duplicate key value violates unique constraint), |
| 136 | +'the error reported by the table sync worker'); |
128 | 137 |
|
129 | 138 | # Test for resetting subscription worker statistics.
|
130 | 139 | # Truncate test_tab1 and test_tab2 so that applying changes and table sync can
|
|