diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm index a589785..904c3a4 100644 --- a/src/test/perl/PostgresNode.pm +++ b/src/test/perl/PostgresNode.pm @@ -175,6 +175,8 @@ sub init if (!defined($params{has_archiving})); $params{allows_streaming} = 0 if (!defined($params{allows_streaming})); + $params{allows_sync_rep} = 0 + if (!defined($params{allows_sync_rep})); mkdir $self->backup_dir; mkdir $self->archive_dir; @@ -198,6 +200,10 @@ sub init print $conf "wal_log_hints = on\n"; print $conf "hot_standby = on\n"; } + if ($params{allows_sync_rep}) + { + print $conf "synchronous_standby_names = 'standby1,standby2'\n"; + } if ($TestLib::windows_os) { diff --git a/src/test/recovery/t/006_multisync_rep.pl b/src/test/recovery/t/006_multisync_rep.pl new file mode 100644 index 0000000..ff23e36 --- /dev/null +++ b/src/test/recovery/t/006_multisync_rep.pl @@ -0,0 +1,84 @@ +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 7; + + +# Initialize master node with synchronous_standby_names = 'standby1,standby2' +my $node_master = get_new_node('master'); +$node_master->init(allows_streaming => 1,allows_sync_rep => 1); +$node_master->start; +my $backup_name = 'my_backup'; + +# Take backup +$node_master->backup($backup_name); + +#Create standby1 linking to master +my $node_standby_1 = get_new_node('standby1'); +$node_standby_1->init_from_backup($node_master, $backup_name, + has_streaming => 1); +$node_standby_1->start; + + +#Create standby2 linking to master +my $node_standby_2 = get_new_node('standby2'); +$node_standby_2->init_from_backup($node_master, $backup_name, + has_streaming => 1); +$node_standby_2->start; + + +# check application sync_state on master initially +my $result = $node_master->psql('postgres', "select application_name, sync_state from pg_stat_replication;"); +print "$result \n"; +is($result, "standby1|sync\nstandby2|potential", 'checked for standbys state for backward compatibility'); + + +#change the s_s_names = '*' and check sync state +$node_master->psql('postgres', "alter system set synchronous_standby_names = '*';"); +$node_master->psql('postgres', "select pg_reload_conf();"); + +$result = $node_master->psql('postgres', "select application_name, sync_state from pg_stat_replication;"); +print "$result \n"; +is($result, "standby1|sync\nstandby2|potential", 'checked for standbys state for backward compatibility'); + + +#change the s_s_names = '2[standby1,standby2]' and check sync state +$node_master->psql('postgres', "alter system set synchronous_standby_names = '2[standby1,standby2]';"); +$node_master->psql('postgres', "select pg_reload_conf();"); + +$result = $node_master->psql('postgres', "select application_name, sync_state from pg_stat_replication;"); +print "$result \n"; +is($result, "standby1|sync\nstandby2|sync", 'checked for sync standbys state'); + +# change the s_s_names = '2[standby1,standby2,*]' and check sync state +$node_master->psql('postgres', "alter system set synchronous_standby_names = '2[standby1,standby2,*]';"); +$node_master->psql('postgres', "select pg_reload_conf();"); + +$result = $node_master->psql('postgres', "select application_name, sync_state from pg_stat_replication;"); +print "$result \n"; +is($result, "standby1|sync\nstandby2|sync", 'checked for sync standbys state'); + + +# change the s_s_names = '2[*]' and check sync state + +$node_master->psql('postgres', "alter system set synchronous_standby_names = '2[*]';"); +$node_master->psql('postgres', "select pg_reload_conf();"); + +$result = $node_master->psql('postgres', "select application_name, sync_state from pg_stat_replication;"); +print "$result \n"; +is($result, "standby1|sync\nstandby2|sync", 'checked for sync standbys state'); + + +#Create some content on master and check its presence on standby 1 and standby 2 +$node_master->psql('postgres', "CREATE TABLE tab_int AS SELECT generate_series(1,1002) AS a"); + + +$result = $node_standby_1->psql('postgres', "SELECT count(*) FROM tab_int"); +print "standby 1: $result\n"; +is($result, qq(1002), 'check synced content on standby 1'); + +$result = $node_standby_1->psql('postgres', "SELECT count(*) FROM tab_int"); +print "standby 2: $result\n"; +is($result, qq(1002), 'check synced content on standby 2');