summaryrefslogtreecommitdiff
path: root/t/02_last_vacuum.t
blob: 806c07a0acf47744be38d931ebe94e67f91cad4c (plain)
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
84
85
86
#!perl

## Test the "last_vacuum" 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 $result $t $host $dbname/;

my $testtbl = 'last_vacuum_test';

my $cp = CP_Testing->new( {default_action => 'last_vacuum'} );

$dbh = $cp->test_database_handle();
$dbname = $cp->get_dbname;
$host = $cp->get_host();
my $ver = $dbh->{pg_server_version};

my $S = q{Action 'last_vacuum'};
my $label = 'POSTGRES_LAST_VACUUM';

SKIP:
{
    $ver < 80200 and skip 'Cannot test last_vacuum on old Postgres versions', 14;

$t = qq{$S self-identifies correctly};
$result = $cp->run(q{-w 0});
like ($result, qr{^$label}, $t);

$t = qq{$S identifies database};
like ($result, qr{DB "$dbname"}, $t);

$t = qq{$S identifies host};
like ($result, qr{host:$host}, $t);

$t = qq{$S accepts valid -w input};
for ('1 second',
     '1 minute',
     '1 hour',
     '1 day'
    ) {
   like ($cp->run(qq{-w "$_"}), qr/^$label/, $t . " ($_)");
}

$t = qq{$S rejects invalid -w input};
for ('-1 second',
     'abc',
    ) {
   like ($cp->run(qq{-w "$_"}), qr/^ERROR:.*?must be a valid time/, $t . " ($_)");
}

$t = qq{$S flags no-match-user};
like ($cp->run(q{-w 0 --includeuser=gandalf}), qr{No matching.*user}, $t);

$t = qq{$S exclude rules work};
$cp->drop_table_if_exists($testtbl);
$dbh->do(qq{CREATE TABLE $testtbl AS SELECT 123::INTEGER AS a FROM generate_series(1,200000)});
$dbh->commit();
like ($cp->run(q{-w 0 --exclude=~.*}),
      qr{No matching tables found due to exclusion}, $t);

$t = qq{$S sees a recent VACUUM};
$dbh->do("DELETE FROM $testtbl");
$dbh->commit();
$dbh->{AutoCommit} = 1;
$dbh->do('VACUUM');
sleep 1;
like ($cp->run("-w 0 --exclude=~.* --include=$testtbl"),
      qr{^$label OK: DB "$dbname" \(host:$host\).*?\(\d+ second(?:s)?\)}, $t);

$t = qq{$S returns correct MRTG information (OK case)};
like ($cp->run("--output=mrtg -w 0 --exclude=~.* --include=$testtbl"),
      qr{\d+\n0\n\n}, $t);

$t = qq{$S returns correct MRTG information (fail case)};
like ($cp->run('--output=mrtg -w 0 --exclude=~.* --include=no_such_table'),
      qr{0\n0\n\n}, $t);

}

exit;