diff --git a/src/test/recovery/t/007_sync_rep.pl b/src/test/recovery/t/007_sync_rep.pl
new file mode 100644
index 0000000..11b2f00
--- /dev/null
+++ b/src/test/recovery/t/007_sync_rep.pl
@@ -0,0 +1,138 @@
+# Minimal test testing synchronous replication sync_state transition
+use strict;
+use warnings;
+
+use PostgresNode;
+use TestLib;
+use Test::More tests => 7;
+
+
+# Initialize master node
+my $node_master = get_new_node('master');
+$node_master->init(allows_streaming => 1);
+$node_master->start;
+my $backup_name = 'master_backup';
+
+my $check_sql = "SELECT application_name, sync_priority, sync_state FROM pg_stat_replication ORDER BY application_name;";
+
+# 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;
+
+# Create standby3 linking to master
+my $node_standby_3 = get_new_node('standby3');
+$node_standby_3->init_from_backup($node_master, $backup_name,
+	has_streaming => 1);
+$node_standby_3->start;
+
+# Check application sync_state on master initially
+$node_master->psql('postgres',
+   "ALTER SYSTEM SET synchronous_standby_names = 'standby1,standby2';");
+$node_master->reload;
+my $result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|sync
+standby2|2|potential
+standby3|0|async),
+   'backward compatibility of synchronous_standby_names');
+
+# Change the synchronous_standby_names = '*' and check synchronous_state.
+$node_master->psql('postgres',
+	"ALTER SYSTEM SET synchronous_standby_names = '*';");
+$node_master->reload;
+
+# Only Standby1 should be in 'sync' state.
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|sync
+standby2|1|potential
+standby3|1|potential),
+	'synchronous_standby_names with asterisk');
+
+# Stop all standbys
+$node_standby_1->stop;
+$node_standby_2->stop;
+$node_standby_3->stop;
+
+# Change the synchronous_standby_names = '2(standby1,standby2,standby3)'
+# and check sync_state.
+$node_master->psql('postgres',
+	"ALTER SYSTEM SET synchronous_standby_names = '2(standby1,standby2,standby3)';");
+$node_master->reload;
+
+$node_standby_2->start;
+$node_standby_3->start;
+
+# standby2 and standby3 should be in 'sync' state.
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby2|2|sync
+standby3|3|sync),
+   '2 synchronous standbys');
+
+$node_standby_1->start;
+
+# Create standby4 linking to master
+my $node_standby_4 = get_new_node('standby4');
+$node_standby_4->init_from_backup($node_master, $backup_name,
+								  has_streaming => 1);
+$node_standby_4->start;
+
+# standby1 should be 'sync' instead of standby3, and standby3 should turn
+# to 'potential'. standby4 should be added in 'async' state.
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|sync
+standby2|2|sync
+standby3|3|potential
+standby4|0|async),
+	'2 synchronous standbys and 1 potential');
+
+# Change the synchronous_standby_names = '2(standby1,*,standby2)' and check
+# synchronous state. This value does not make actually much sense but
+# synchronous_standby_names can accept it, and this test is for checking
+# backward compatibility.
+$node_master->safe_psql('postgres',
+	"ALTER SYSTEM SET synchronous_standby_names = '2(standby1,*,standby2)';");
+$node_master->reload;
+
+# Standby1 and standby2 should be 'sync', and sync_priority of standby2
+# should be 2, not 3.
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|sync
+standby2|2|sync
+standby3|2|potential
+standby4|2|potential),
+	'synchronous_standby_names with asterisk and potential standbys');
+
+# Change the synchronous_standby_names = '2(*)' and check sync state
+$node_master->psql('postgres',
+	"ALTER SYSTEM SET synchronous_standby_names = '2(*)';");
+$node_master->reload;
+
+# Since standby2 and standby3 have higher index number of WalSnd array,
+# these standbys should be 'sync' instead of standby1.
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|potential
+standby2|1|sync
+standby3|1|sync
+standby4|1|potential),
+   'synchronous_standby_names with asterisk and potential standby');
+
+# Stop Standby3 which is considered in 'sync' state.
+$node_standby_3->stop;
+
+# Standby1 become 'sync'
+$result = $node_master->safe_psql('postgres', $check_sql);
+is($result, qq(standby1|1|sync
+standby2|1|sync
+standby4|1|potential),
+	'synchronous_standby_names with asterisk, previous potential becoming sync');
