Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 55ba564

Browse files
committed
Improve test coverage of pg_rewind
This includes new TAP tests for a couple of areas not covered yet and some improvements: - More coverage for --no-ensure-shutdown, the enforced recovery step and --dry-run. - Failures with option combinations and basic option checks. - Removal of a duplicated comment. Author: Alexey Kondratov, Michael Paquier Discussion: https://postgr.es/m/20191007010651.GD14532@paquier.xyz
1 parent 47eec34 commit 55ba564

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

src/bin/pg_rewind/t/001_basic.pl

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33
use TestLib;
4-
use Test::More tests => 11;
4+
use Test::More tests => 15;
55

66
use FindBin;
77
use lib $FindBin::RealBin;
@@ -66,6 +66,71 @@ sub run_test
6666
master_psql("DELETE FROM tail_tbl WHERE id > 10");
6767
master_psql("VACUUM tail_tbl");
6868

69+
# Before running pg_rewind, do a couple of extra tests with several
70+
# option combinations. As the code paths taken by those tests
71+
# do not change for the "local" and "remote" modes, just run them
72+
# in "local" mode for simplicity's sake.
73+
if ($test_mode eq 'local')
74+
{
75+
my $master_pgdata = $node_master->data_dir;
76+
my $standby_pgdata = $node_standby->data_dir;
77+
78+
# First check that pg_rewind fails if the target cluster is
79+
# not stopped as it fails to start up for the forced recovery
80+
# step.
81+
command_fails(
82+
[
83+
'pg_rewind', '--debug',
84+
'--source-pgdata', $standby_pgdata,
85+
'--target-pgdata', $master_pgdata,
86+
'--no-sync'
87+
],
88+
'pg_rewind with running target');
89+
90+
# Again with --no-ensure-shutdown, which should equally fail.
91+
# This time pg_rewind complains without attempting to perform
92+
# recovery once.
93+
command_fails(
94+
[
95+
'pg_rewind', '--debug',
96+
'--source-pgdata', $standby_pgdata,
97+
'--target-pgdata', $master_pgdata,
98+
'--no-sync', '--no-ensure-shutdown'
99+
],
100+
'pg_rewind --no-ensure-shutdown with running target');
101+
102+
# Stop the target, and attempt to run with a local source
103+
# still running. This fails as pg_rewind requires to have
104+
# a source cleanly stopped.
105+
$node_master->stop;
106+
command_fails(
107+
[
108+
'pg_rewind', '--debug',
109+
'--source-pgdata', $standby_pgdata,
110+
'--target-pgdata', $master_pgdata,
111+
'--no-sync', '--no-ensure-shutdown'
112+
],
113+
'pg_rewind with unexpected running source');
114+
115+
# Stop the target cluster cleanly, and run again pg_rewind
116+
# with --dry-run mode. If anything gets generated in the data
117+
# folder, the follow-up run of pg_rewind will most likely fail,
118+
# so keep this test as the last one of this subset.
119+
$node_standby->stop;
120+
command_ok(
121+
[
122+
'pg_rewind', '--debug',
123+
'--source-pgdata', $standby_pgdata,
124+
'--target-pgdata', $master_pgdata,
125+
'--no-sync', '--dry-run'
126+
],
127+
'pg_rewind --dry-run');
128+
129+
# Both clusters need to be alive moving forward.
130+
$node_standby->start;
131+
$node_master->start;
132+
}
133+
69134
RewindTest::run_pg_rewind($test_mode);
70135

71136
check_query(

src/bin/pg_rewind/t/005_same_timeline.pl

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
use RewindTest;
1414

15-
# Test that running pg_rewind if the two clusters are on the same
16-
# timeline runs successfully.
17-
1815
RewindTest::setup_cluster();
1916
RewindTest::start_master();
2017
RewindTest::create_standby();

src/bin/pg_rewind/t/006_options.pl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Test checking options of pg_rewind.
3+
#
4+
use strict;
5+
use warnings;
6+
use TestLib;
7+
use Test::More tests => 12;
8+
9+
program_help_ok('pg_rewind');
10+
program_version_ok('pg_rewind');
11+
program_options_handling_ok('pg_rewind');
12+
13+
my $primary_pgdata = TestLib::tempdir;
14+
my $standby_pgdata = TestLib::tempdir;
15+
command_fails(
16+
[
17+
'pg_rewind', '--debug',
18+
'--target-pgdata', $primary_pgdata,
19+
'--source-pgdata', $standby_pgdata,
20+
'extra_arg1'
21+
],
22+
'too many arguments');
23+
command_fails([ 'pg_rewind', '--target-pgdata', $primary_pgdata ],
24+
'no source specified');
25+
command_fails(
26+
[
27+
'pg_rewind', '--debug',
28+
'--target-pgdata', $primary_pgdata,
29+
'--source-pgdata', $standby_pgdata,
30+
'--source-server', 'incorrect_source'
31+
],
32+
'both remote and local sources specified');
33+
command_fails(
34+
[
35+
'pg_rewind', '--debug',
36+
'--target-pgdata', $primary_pgdata,
37+
'--source-pgdata', $standby_pgdata,
38+
'--write-recovery-conf'
39+
],
40+
'no local source with --write-recovery-conf');

0 commit comments

Comments
 (0)