Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb5089a

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

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::Moretests=> 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+
subcommand_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)

[8]ページ先頭

©2009-2025 Movatter.jp