1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Improvements and additional tests for stanza-upgrade.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang
2017-04-06 19:36:37 -04:00
committed by David Steele
parent 0da216c034
commit b620e6b282
21 changed files with 584 additions and 278 deletions
@@ -0,0 +1,104 @@
####################################################################################################################################
# BackupInfoUnitTest.pm - Unit tests for BackupInfo
####################################################################################################################################
package pgBackRestTest::Backup::BackupInfoUnitTest;
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
####################################################################################################################################
# Perl includes
####################################################################################################################################
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
use File::Basename qw(dirname);
use Storable qw(dclone);
use pgBackRest::BackupInfo;
use pgBackRest::Common::Exception;
use pgBackRest::Common::Lock;
use pgBackRest::Common::Log;
use pgBackRest::DbVersion;
use pgBackRest::File;
use pgBackRest::FileCommon;
use pgBackRest::InfoCommon;
use pgBackRest::Manifest;
use pgBackRest::Protocol::Common;
use pgBackRest::Protocol::Protocol;
use pgBackRestTest::Common::Env::EnvHostTest;
use pgBackRestTest::Common::ExecuteTest;
use pgBackRestTest::Common::Host::HostBackupTest;
use pgBackRestTest::Common::RunTest;
####################################################################################################################################
# initModule
####################################################################################################################################
sub initModule
{
my $self = shift;
$self->{strDbPath} = $self->testPath() . '/db';
$self->{strRepoPath} = $self->testPath() . '/repo';
$self->{strArchivePath} = "$self->{strRepoPath}/archive/" . $self->stanza();
$self->{strBackupPath} = "$self->{strRepoPath}/backup/" . $self->stanza();
$self->{strSpoolPath} = "$self->{strArchivePath}/out";
}
####################################################################################################################################
# initTest
####################################################################################################################################
sub initTest
{
my $self = shift;
# Create archive info path
filePathCreate($self->{strArchivePath}, undef, true, true);
# Create backup info path
filePathCreate($self->{strBackupPath}, undef, true, true);
# Create pg_control path
filePathCreate(($self->{strDbPath} . '/' . DB_PATH_GLOBAL), undef, false, true);
# Copy a pg_control file into the pg_control path
executeTest(
'cp ' . $self->dataPath() . '/backup.pg_control_' . WAL_VERSION_94 . '.bin ' . $self->{strDbPath} . '/' .
DB_FILE_PGCONTROL);
}
####################################################################################################################################
# run
####################################################################################################################################
sub run
{
my $self = shift;
# Increment the run, log, and decide whether this unit test should be run
################################################################################################################################
if ($self->begin("BackupInfo::confirmDb()"))
{
my $oBackupInfo = new pgBackRest::BackupInfo($self->{strBackupPath}, false, false);
$oBackupInfo->create(PG_VERSION_93, WAL_VERSION_93_SYS_ID, '937', '201306121', true);
my $strBackupLabel = "20170403-175647F";
$oBackupInfo->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_HISTORY_ID,
$oBackupInfo->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_HISTORY_ID));
#---------------------------------------------------------------------------------------------------------------------------
$self->testResult(sub {$oBackupInfo->confirmDb($strBackupLabel, PG_VERSION_93, WAL_VERSION_93_SYS_ID,)}, true,
'backup db matches');
#---------------------------------------------------------------------------------------------------------------------------
$self->testResult(sub {$oBackupInfo->confirmDb($strBackupLabel, PG_VERSION_94, WAL_VERSION_93_SYS_ID,)}, false,
'backup db wrong version');
#---------------------------------------------------------------------------------------------------------------------------
$self->testResult(sub {$oBackupInfo->confirmDb($strBackupLabel, PG_VERSION_93, WAL_VERSION_94_SYS_ID,)}, false,
'backup db wrong system-id');
}
}
1;
@@ -309,6 +309,11 @@ my $oTestDef =
&TESTDEF_TEST_TOTAL => 3,
&TESTDEF_TEST_INDIVIDUAL => false,
},
{
&TESTDEF_TEST_NAME => 'info-unit',
&TESTDEF_TEST_TOTAL => 1,
&TESTDEF_TEST_INDIVIDUAL => false,
},
]
},
# Expire tests
@@ -208,6 +208,11 @@ sub run
$oExpireTest->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY);
$oExpireTest->process($self->stanza(), 3, 1, BACKUP_TYPE_DIFF, 1, $strDescription);
#-----------------------------------------------------------------------------------------------------------------------
$strDescription = 'Expire all archive except for the current database';
$oExpireTest->process($self->stanza(), 2, undef, BACKUP_TYPE_FULL, undef, $strDescription);
#-----------------------------------------------------------------------------------------------------------------------
$self->optionReset($oOption, OPTION_DB_PATH);
$self->optionReset($oOption, OPTION_ONLINE);
@@ -1,5 +1,5 @@
####################################################################################################################################
# ArchivePushUnitTest.pm - Unit tests for ArchivePush and ArchivePush Async
# StanzaUnitTest.pm - Unit tests for Stanza.pm
####################################################################################################################################
package pgBackRestTest::Stanza::StanzaUnitTest;
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
@@ -151,11 +151,16 @@ sub run
$oHostBackup->stanzaUpgrade('successfully upgrade with XX.Y-Z', {strOptionalParam => '--no-' . OPTION_ONLINE});
# Push a WAL and create a backup in the new DB to confirm info command displays the JSON correctly
# Push a WAL and create a backup in the new DB to confirm diff changed to full and info command displays the JSON correctly
#--------------------------------------------------------------------------------------------------------------------------
$oHostDbMaster->archivePush($strXlogPath, $strArchiveTestFile . WAL_VERSION_95 . '.bin', 1);
$oHostBackup->backup('full', 'create second full backup ', {strOptionalParam => '--retention-full=2 --no-' .
OPTION_ONLINE . ' --log-level-console=detail'}, false);
# Test backup is changed from type=DIFF to FULL (WARN message displayed)
my $oExecuteBackup = $oHostBackup->backupBegin('diff', 'diff changed to full backup',
{strOptionalParam => '--retention-full=2 --no-' . OPTION_ONLINE . ' --log-level-console=detail'});
$oHostBackup->backupEnd('full', $oExecuteBackup, undef, false);
# Confirm info command displays the JSON correctly
$oHostDbMaster->info('db upgraded - db-1 and db-2 listed', {strOutput => INFO_OUTPUT_JSON});
}
}