Skip to content

Commit eb5089a

Browse files
committed
pg_ctl: Add tests for promote action
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent e767db2 commit eb5089a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/bin/pg_ctl/t/003_promote.pl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 9;
7+
8+
my $tempdir = TestLib::tempdir;
9+
10+
command_fails_like([ 'pg_ctl', '-D', "$tempdir/nonexistent", 'promote' ],
11+
qr/directory .* does not exist/,
12+
'pg_ctl promote with nonexistent directory');
13+
14+
my $node_primary = get_new_node('primary');
15+
$node_primary->init(allows_streaming => 1);
16+
17+
command_fails_like([ 'pg_ctl', '-D', $node_primary->data_dir, 'promote' ],
18+
qr/PID file .* does not exist/,
19+
'pg_ctl promote of not running instance fails');
20+
21+
$node_primary->start;
22+
23+
command_fails_like([ 'pg_ctl', '-D', $node_primary->data_dir, 'promote' ],
24+
qr/not in standby mode/,
25+
'pg_ctl promote of primary instance fails');
26+
27+
my $node_standby = get_new_node('standby');
28+
$node_primary->backup('my_backup');
29+
$node_standby->init_from_backup($node_primary, 'my_backup', has_streaming => 1);
30+
$node_standby->start;
31+
32+
is($node_standby->safe_psql('postgres', 'SELECT pg_is_in_recovery()'),
33+
't', 'standby is in recovery');
34+
35+
command_ok([ 'pg_ctl', '-D', $node_standby->data_dir, 'promote' ],
36+
'pg_ctl promote of standby runs');
37+
38+
ok($node_standby->poll_query_until('postgres', 'SELECT NOT pg_is_in_recovery()'),
39+
'promoted standby is not in recovery');

src/test/perl/TestLib.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ our @EXPORT = qw(
3434
program_version_ok
3535
program_options_handling_ok
3636
command_like
37+
command_fails_like
3738
3839
$windows_os
3940
);
@@ -281,4 +282,14 @@ sub command_like
281282
like($stdout, $expected_stdout, "$test_name: matches");
282283
}
283284

285+
sub command_fails_like
286+
{
287+
my ($cmd, $expected_stderr, $test_name) = @_;
288+
my ($stdout, $stderr);
289+
print("# Running: " . join(" ", @{$cmd}) . "\n");
290+
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
291+
ok(!$result, "$test_name: exit code not 0");
292+
like($stderr, $expected_stderr, "$test_name: matches");
293+
}
294+
284295
1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy