1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!perl
## Test the "checkpoint" action
use 5.006;
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 14;
use lib 't','.';
use CP_Testing;
use vars qw/$dbh $SQL $t/;
my $cp = CP_Testing->new( {default_action => 'checkpoint'} );
$dbh = $cp->test_database_handle();
my $S = q{Action 'checkpoint'};
my $label = 'POSTGRES_CHECKPOINT';
$t=qq{$S fails when called with an invalid option};
like ($cp->run('foobar=12'), qr{Usage:}, $t);
$t=qq{$S fails when called without warning or critical};
like ($cp->run(''), qr{Must provide a warning and/or critical}, $t);
$t=qq{$S fails when called with invalid warning option};
like ($cp->run('-w foo'), qr{ERROR: .+'warning'.+valid time}, $t);
$t=qq{$S fails when called with invalid critical option};
like ($cp->run('-c foo'), qr{ERROR: .+'critical'.+valid time}, $t);
$t=qq{$S fails when called without a datadir option and PGDATA is not set};
delete $ENV{PGDATA};
like ($cp->run('-c 10'), qr{^ERROR: Must supply a --datadir}, $t);
$t=qq{$S fails when called with an invalid datadir option and PGDATA is not set};
like ($cp->run('-c 10 --datadir=foobar'), qr{^ERROR: Invalid data_directory}, $t);
my $host = $cp->get_dbhost();
$t=qq{$S fails when called against a non datadir datadir};
like ($cp->run(qq{-c 10 --datadir="$host"}), qr{^ERROR:.+could not read the given data directory}, $t);
$t=qq{$S works when called for a recent checkpoint};
my $dbh = $cp->get_dbh();
$dbh->do('CHECKPOINT');
$dbh->commit();
$host =~ s/socket$//;
my $result = $cp->run(qq{-w 30 --datadir="$host"});
SKIP:
{
if ($result =~ /Date::Parse/) {
skip 'Cannot test checkpoint action unless Date::Parse module is installed', 6;
}
like ($cp->run(qq{-w 30 --datadir="$host"}), qr{^$label OK}, $t);
$t=qq{$S returns a warning when checkpoint older than warning option};
sleep 2;
like ($cp->run(qq{-w 1 --datadir="$host"}), qr{^$label WARNING:}, $t);
$t=qq{$S returns a critical when checkpoint older than critical option};
like ($cp->run(qq{-c 1 --datadir="$host"}), qr{^$label CRITICAL:}, $t);
# FIXME: no check for --assume-prod, it needs to have a cluster in this state
$t=qq{$S returns a critical when --assume-standby-mode on a non-standby};
like ($cp->run(qq{-c 1000 --datadir="$host" --assume-standby-mode}), qr{^$label CRITICAL:.*mode=NOT STANDBY}, $t);
$t=qq{$S returns the correct number of seconds};
like ($cp->run(qq{-c 1 --datadir="$host"}), qr{was \d+ seconds ago}, $t);
$t=qq{$S returns the expected output for MRTG};
like ($cp->run(qq{-c 1 --output=MRTG --datadir="$host"}), qr{^\d+\n0\n\nLast checkpoint was \d+ seconds ago}, $t);
$t=qq{$S returns the expected output for MRTG};
like ($cp->run(qq{-c 199 --output=MRTG --datadir="$host"}), qr{^\d+\n0\n\nLast checkpoint was \d+ seconds ago}, $t);
}
exit;
|