]> granicus.if.org Git - postgresql/blob - src/bin/pg_rewind/t/002_databases.pl
Refactor and fix TAP tests of pg_rewind
[postgresql] / src / bin / pg_rewind / t / 002_databases.pl
1 use strict;
2 use warnings;
3 use TestLib;
4 use Test::More tests => 4;
5
6 use RewindTest;
7
8 sub run_test
9 {
10         my $test_mode = shift;
11
12         RewindTest::init_rewind_test('databases', $test_mode);
13         RewindTest::setup_cluster();
14
15         # Create a database in master.
16         master_psql('CREATE DATABASE inmaster');
17
18         RewindTest::create_standby();
19
20         # Create another database, the creation is replicated to the standby
21         master_psql('CREATE DATABASE beforepromotion');
22
23         RewindTest::promote_standby();
24
25         # Create databases in the old master and the new promoted standby.
26         master_psql('CREATE DATABASE master_afterpromotion');
27         standby_psql('CREATE DATABASE standby_afterpromotion');
28         # The clusters are now diverged.
29
30         RewindTest::run_pg_rewind($test_mode);
31
32         # Check that the correct databases are present after pg_rewind.
33         check_query('SELECT datname FROM pg_database',
34                            qq(template1
35 template0
36 postgres
37 inmaster
38 beforepromotion
39 standby_afterpromotion
40 ),
41                            'database names');
42
43 }
44
45 # Run the test in both modes.
46 run_test('local');
47 run_test('remote');
48
49 exit(0);