|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 24; |
| 6 | +use Test::More tests => 28; |
7 | 7 |
|
8 | 8 | # Initialize master node
|
9 | 9 | my $node_master = get_new_node('master');
|
|
59 | 59 | is($node_standby_2->psql('postgres', 'INSERT INTO tab_int VALUES (1)'),
|
60 | 60 | 3, 'read-only queries on standby 2');
|
61 | 61 |
|
| 62 | +# Tests for connection parameter target_session_attrs |
| 63 | +diag "testing connection parameter \"target_session_attrs\""; |
| 64 | + |
| 65 | +# Routine designed to run tests on the connection parameter |
| 66 | +# target_session_attrs with multiple nodes. |
| 67 | +sub test_target_session_attrs |
| 68 | +{ |
| 69 | + my $node1 = shift; |
| 70 | + my $node2 = shift; |
| 71 | + my $target_node = shift; |
| 72 | + my $mode = shift; |
| 73 | + my $status = shift; |
| 74 | + |
| 75 | + my $node1_host = $node1->host; |
| 76 | + my $node1_port = $node1->port; |
| 77 | + my $node1_name = $node1->name; |
| 78 | + my $node2_host = $node2->host; |
| 79 | + my $node2_port = $node2->port; |
| 80 | + my $node2_name = $node2->name; |
| 81 | + |
| 82 | + my $target_name = $target_node->name; |
| 83 | + |
| 84 | + # Build connection string for connection attempt. |
| 85 | + my $connstr = "host=$node1_host,$node2_host "; |
| 86 | + $connstr .= "port=$node1_port,$node2_port "; |
| 87 | + $connstr .= "target_session_attrs=$mode"; |
| 88 | + |
| 89 | + # The client used for the connection does not matter, only the backend |
| 90 | + # point does. |
| 91 | + my ($ret, $stdout, $stderr) = |
| 92 | + $node1->psql('postgres', 'SHOW port;', extra_params => ['-d', $connstr]); |
| 93 | + is($status == $ret && $stdout eq $target_node->port, 1, |
| 94 | + "connect to node $target_name if mode \"$mode\" and $node1_name,$node2_name listed"); |
| 95 | +} |
| 96 | + |
| 97 | +# Connect to master in "read-write" mode with master,standby1 list. |
| 98 | +test_target_session_attrs($node_master, $node_standby_1, $node_master, |
| 99 | + "read-write", 0); |
| 100 | +# Connect to master in "read-write" mode with standby1,master list. |
| 101 | +test_target_session_attrs($node_standby_1, $node_master, $node_master, |
| 102 | + "read-write", 0); |
| 103 | +# Connect to master in "any" mode with master,standby1 list. |
| 104 | +test_target_session_attrs($node_master, $node_standby_1, $node_master, |
| 105 | + "any", 0); |
| 106 | +# Connect to standby1 in "any" mode with standby1,master list. |
| 107 | +test_target_session_attrs($node_standby_1, $node_master, $node_standby_1, |
| 108 | + "any", 0); |
| 109 | + |
62 | 110 | diag "switching to physical replication slot";
|
63 | 111 | # Switch to using a physical replication slot. We can do this without a new
|
64 | 112 | # backup since physical slots can go backwards if needed. Do so on both
|
|
0 commit comments