Skip to content

Commit

Permalink
Fix and update TAP tests
Browse files Browse the repository at this point in the history
TAP tests are currently compatible down to PostgreSQL 8.2.
  • Loading branch information
ioguix committed Jun 30, 2022
1 parent b4717b6 commit c78e24e
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 61 deletions.
27 changes: 23 additions & 4 deletions t/01-archive_folder.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,37 @@ my $wal;
my $time;

# create the instance and start it
$node->init(has_archiving => 1, allows_streaming => 1);
$node->init(has_archiving => 1);

if ( $node->version >= 9.6 ) {
$node->append_conf('postgresql.conf', "wal_level = replica");
}
elsif ( $node->version >= 9.0 ) {
$node->append_conf('postgresql.conf', "wal_level = archive");
}

$node->start;

# generate three archives
# split create table and insert to produce more data in WAL
$node->psql('template1', 'create table t (i int primary key)');
$node->psql('template1', 'insert into t select generate_series(1,10000) i');
$node->psql('template1', 'insert into t select generate_series(1,10000) as i');
$node->switch_wal;
$node->psql('template1', 'insert into t select generate_series(10001,20000) i');
$node->psql('template1', 'insert into t select generate_series(10001,20000) as i');
$node->switch_wal;
$node->psql('template1', 'insert into t select generate_series(20001,30000) i');
$node->psql('template1', 'insert into t select generate_series(20001,30000) as i');
$wal = $node->switch_wal;

# The WAL sequence starts at 000000010000000000000000 up to v8.4, then
# 000000010000000000000001 starting from v9.0.
# Make sure we have the exact same archive sequence whatever the version so
# following tests apply no matter the version.
if ($node->version < 9.0) {
$node->psql('template1', 'insert into t select generate_series(30001,40000) as i');
$wal = $node->switch_wal;
unlink "$archive_dir/000000010000000000000000";
}

$node->wait_for_archive($wal);

### Begin of tests ###
Expand Down
26 changes: 22 additions & 4 deletions t/01-archiver.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,35 @@ my $pga_data = "$TestLib::tmp_check/pga.data";
my $wal;
my @stdout;

$node->init(has_archiving => 1, allows_streaming => 1);
$node->init(has_archiving => 1);

if ( $node->version >= 9.6 ) {
$node->append_conf('postgresql.conf', "wal_level = replica");
}
elsif ( $node->version >= 9.0 ) {
$node->append_conf('postgresql.conf', "wal_level = archive");
}

$node->start;

### Begin of tests ###

# generate one archive
# split create table and insert to produce more data in WAL
$node->psql('template1', 'create table t (i int primary key)');
$node->psql('template1', 'insert into t select generate_series(1,10000) i');
$node->psql('template1', 'insert into t select generate_series(1,10000) as i');
$wal = $node->switch_wal;


# The WAL sequence starts at 000000010000000000000000 up to v8.4, then
# 000000010000000000000001 starting from v9.0.
# Make sure we have the exact same archive sequence whatever the version so
# following tests apply no matter the version.
if ($node->version < 9.0) {
$node->psql('template1', 'insert into t select generate_series(-1000,0) as i');
$wal = $node->switch_wal;
}

# FIXME: there's a race condition in archiver check when it get the mtime
# of the next WAL to archive while it hasn't been created yet.
# Write a checkpoint to force the creation of the new WAL.
Expand Down Expand Up @@ -58,7 +76,7 @@ $node->command_checks_all( [
$node->append_conf('postgresql.conf', "archive_command = 'false'");
$node->reload;

$node->psql('template1', 'insert into t select generate_series(10001,20000) i');
$node->psql('template1', 'insert into t select generate_series(10001,20000) as i');
$wal = $node->switch_wal;
# avoid same race condition
$node->psql('template1', 'checkpoint');
Expand All @@ -74,7 +92,7 @@ TestLib::system_or_bail('./check_pgactivity',
'--port' => $node->port,
'--status-file' => $pga_data,
'--format' => 'human'
) if $node->version <= 9.6;
) if $node->version < 10;

@stdout = (
qr/^Service *: POSTGRES_ARCHIVER$/m,
Expand Down
33 changes: 22 additions & 11 deletions t/01-autovacuum.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ plan tests => $num_tests + 3;
### Begin of tests ###

$node->init;
$node->start;

# Tests for PostreSQL 8.0 and before
SKIP: {
# "skip" allows to ignore the whole bloc based on the given a condition
skip "skip non-compatible test on PostgreSQL 8.0 and before", 3
skip "testing incompatibility with PostgreSQL 8.0 and before", 3
unless $node->version <= 8.0;

$node->start;
$node->command_checks_all( [
'./check_pgactivity', '--service' => 'autovacuum',
'--username' => getlogin,
Expand All @@ -47,6 +46,15 @@ SKIP: {
skip "these tests requires PostgreSQL 8.1 and after", $num_tests
unless $node->version >= 8.1;

if ($node->version < 8.3) {
$node->append_conf('postgresql.conf',
qq{autovacuum = on\n}
.qq{stats_row_level = on}
);
}

$node->start;

@stdout = (
qr/^Service *: POSTGRES_AUTOVACUUM$/m,
qr/^Returns *: 0 \(OK\)$/m,
Expand All @@ -56,11 +64,19 @@ SKIP: {
qr/^Perfdata *: VACUUM=[0-3]$/m,
qr/^Perfdata *: ANALYZE=[0-3]$/m,
qr/^Perfdata *: oldest_autovacuum=(NaN|\d+)s$/m,
qr/^Perfdata *: max_workers=3$/m
);

push @stdout, qr/^Perfdata *: BRIN_SUMMARIZE=[0-3]$/m
if $node->version > 9.6;
SKIP: {
skip "No max_worker before PgSQL 8.3", 1
if $node->version < 8.3;
push @stdout, qr/^Perfdata *: max_workers=3$/m;
}

SKIP: {
skip "No autovacuum brin summarize before PgSQL 10", 1
if $node->version < 10;
push @stdout, qr/^Perfdata *: BRIN_SUMMARIZE=[0-3]$/m;
}

$node->command_checks_all( [
'./check_pgactivity', '--service' => 'autovacuum',
Expand All @@ -73,11 +89,6 @@ SKIP: {
'basic check without thresholds'
);

{
skip "No autovacuum brin summarize before PgSQL 10", 1
if $node->version < 10;
}

$node->stop;
}

Expand Down
2 changes: 1 addition & 1 deletion t/01-backends.t
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $node->command_checks_all( [
);

# add two new backends and test warning
push( @procs, pgSession->new($node) ) for (1..2);
push( @procs, pgSession->new($node) ) for 1..2;

$node->command_checks_all( [
'./check_pgactivity', '--service' => 'backends',
Expand Down
4 changes: 4 additions & 0 deletions t/01-hit_ratio.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ my $node = pgNode->get_new_node('prod');
my $pga_data = "$TestLib::tmp_check/pga.data";

$node->init;

$node->append_conf('postgresql.conf', 'stats_block_level = on')
if $node->version < 8.3;

$node->start;

### Begin of tests ###
Expand Down
96 changes: 73 additions & 23 deletions t/01-last_analyze.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ use TestLib ();
use Test::More tests => 33;

my $node = pgNode->get_new_node('prod');
my $pga_data = "$TestLib::tmp_check/pga.data";
my $stdout;
my @stdout;

$node->init;

$node->append_conf('postgresql.conf', 'stats_row_level = on')
if $node->version < 8.3;

$node->start;

### Begin of tests ###
Expand Down Expand Up @@ -44,6 +51,7 @@ $node->command_checks_all( [
'--username' => getlogin,
'--format' => 'human',
'--dbname' => 'template1',
'--status-file' => $pga_data,
'--warning' => '1h',
'--critical' => '10d'
],
Expand All @@ -59,24 +67,52 @@ $node->command_checks_all( [

# test database with one table never analyzed

# we must track the stat activity on pg_class to make sure there was some stat
# activity to avoid the check_pga shortcut when no activity.
($stdout) = $node->psql('testdb', q{
SELECT n_tup_ins
FROM pg_stat_sys_tables
WHERE relname = 'pg_class'
});

$node->psql('testdb', 'CREATE TABLE foo (bar INT PRIMARY KEY)');

$node->poll_query_until('testdb', qq{
SELECT n_tup_ins > $stdout
FROM pg_stat_sys_tables
WHERE relname = 'pg_class'
});

@stdout = (
qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 2 \(CRITICAL\)$/m,
qr/^Message *: testdb: Infinity$/m,
qr/^Perfdata *: testdb=Infinitys warn=3600 crit=864000$/m
);

SKIP: {
# skip **all** the tests in this files about analyze counts if < 9.1,
# not just the two following below, so we avoid repeating this SKIP block.
skip "No analyze counts PgSQL 9.1", 6
if $node->version < 9.1;

push @stdout, (
qr/^Perfdata *: testdb analyze=0$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m
);
}

$node->command_checks_all( [
'./check_pgactivity', '--service' => 'last_analyze',
'--username' => getlogin,
'--format' => 'human',
'--dbname' => 'testdb',
'--status-file' => $pga_data,
'--warning' => '1h',
'--critical' => '10d'
],
2,
[ qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 2 \(CRITICAL\)$/m,
qr/^Message *: testdb: Infinity$/m,
qr/^Perfdata *: testdb=Infinitys warn=3600 crit=864000$/m,
qr/^Perfdata *: testdb analyze=0$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m,
],
\@stdout,
[ qr/^$/ ],
'database with one table never analyzed'
);
Expand All @@ -88,27 +124,34 @@ $node->psql('testdb', 'INSERT INTO titi SELECT generate_series(1,1000)');
$node->psql('testdb', 'ANALYZE titi');

$node->poll_query_until('testdb', q{
SELECT analyze_count > 0
SELECT last_analyze IS NOT NULL
FROM pg_catalog.pg_stat_user_tables
WHERE relname = 'titi'
});

@stdout = (
qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 2 \(CRITICAL\)$/m,
qr/^Message *: testdb: Infinity$/m,
qr/^Perfdata *: testdb=Infinitys warn=3600 crit=864000$/m
);

push @stdout, (
qr/^Perfdata *: testdb analyze=1$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m
) if $node->version >= 9.1;

$node->command_checks_all( [
'./check_pgactivity', '--service' => 'last_analyze',
'--username' => getlogin,
'--format' => 'human',
'--dbname' => 'testdb',
'--status-file' => $pga_data,
'--warning' => '1h',
'--critical' => '10d'
],
2,
[ qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 2 \(CRITICAL\)$/m,
qr/^Message *: testdb: Infinity$/m,
qr/^Perfdata *: testdb=Infinitys warn=3600 crit=864000$/m,
qr/^Perfdata *: testdb analyze=1$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m,
],
\@stdout,
[ qr/^$/ ],
'database with two tables, one never analyzed'
);
Expand All @@ -118,27 +161,34 @@ $node->command_checks_all( [
$node->psql('testdb', 'ANALYZE foo');

$node->poll_query_until('testdb', q{
SELECT sum(analyze_count) = 2
SELECT count(last_analyze) = 2
FROM pg_catalog.pg_stat_user_tables
WHERE relname IN ('foo', 'titi')
});

@stdout = (
qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 0 \(OK\)$/m,
qr/^Message *: 1 database\(s\) checked$/m,
qr/^Perfdata *: testdb=.*s warn=3600 crit=864000$/m
);

push @stdout, (
qr/^Perfdata *: testdb analyze=1$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m
) if $node->version >= 9.1;

$node->command_checks_all( [
'./check_pgactivity', '--service' => 'last_analyze',
'--username' => getlogin,
'--format' => 'human',
'--dbname' => 'testdb',
'--status-file' => $pga_data,
'--warning' => '1h',
'--critical' => '10d'
],
0,
[ qr/^Service *: POSTGRES_LAST_ANALYZE$/m,
qr/^Returns *: 0 \(OK\)$/m,
qr/^Message *: 1 database\(s\) checked$/m,
qr/^Perfdata *: testdb=.*s warn=3600 crit=864000$/m,
qr/^Perfdata *: testdb analyze=1$/m,
qr/^Perfdata *: testdb autoanalyze=0$/m,
],
\@stdout,
[ qr/^$/ ],
'test database with two tables, both analyzed'
);
Expand Down
17 changes: 10 additions & 7 deletions t/01-streaming_delta.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ my $pgversion;
$pgversion = $prim->version;
note "testing on version $pgversion";

# create primary and start it
$prim->init(allows_streaming => 1);
$prim->start;
note("primary started");

# Tests for PostreSQL 9.0 and before
SKIP: {
# "skip" allows to ignore the whole bloc based on the given a condition
skip "skip non-compatible test on PostgreSQL 9.0 and before", 3
unless $prim->version <= '9.0';
unless $pgversion <= '9.0';

$prim->init;
$prim->start;

$prim->command_checks_all( [
'./check_pgactivity', '--service' => 'streaming_delta',
Expand All @@ -54,7 +52,12 @@ SKIP: {
# Tests for PostreSQL 9.1 and after
SKIP: {
skip "these tests requires PostgreSQL 9.1 and after", $num_tests
unless $prim->version >= '9.1';
unless $pgversion >= '9.1';

# create primary and start it
$prim->init(allows_streaming => 1);
$prim->start;
note("primary started");

# create backup
$prim->backup($backup);
Expand Down
Loading

0 comments on commit c78e24e

Please sign in to comment.