mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-02-03 13:21:32 +02:00
de816a0f57
Integration expect log testing was originally used as a rough-and-ready way to make sure that certain code paths were being executed before the unit tests existed. Now that we have 100% unit test coverage (with expect log testing) the value of the integration expect tests seems minimal at best. But they do cause numerous issues: - Maintenance of the expect code and replacements that are required to keep logs reproducible. - Even a trivial change can cause massive churn in the expect logs, e.g. d9088b2. These changes should be minutely audited but since the expect logs have little value now it is seldom worth the effort. - The OS version used to do expect testing (RHEL7) can only be used to test one version of PostgreSQL. This makes it hard to balance the PostgreSQL version testing between OS versions. - When a commit affects expect logs it is not clear (especially for new developers) how to regenerate them and our contributing guide is silent on the issue. The goal is to migrate the integration tests to C and expect testing is not part of that plan. It seems best to get rid of them now.
218 lines
7.8 KiB
Perl
218 lines
7.8 KiB
Perl
####################################################################################################################################
|
|
# HostDbTest.pm - Database host
|
|
####################################################################################################################################
|
|
package pgBackRestTest::Env::Host::HostDbCommonTest;
|
|
use parent 'pgBackRestTest::Env::Host::HostBackupTest';
|
|
|
|
####################################################################################################################################
|
|
# Perl includes
|
|
####################################################################################################################################
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw();
|
|
use File::Basename qw(dirname);
|
|
use Storable qw(dclone);
|
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
use pgBackRestDoc::Common::Ini;
|
|
use pgBackRestDoc::Common::Log;
|
|
use pgBackRestDoc::Common::String;
|
|
use pgBackRestDoc::ProjectInfo;
|
|
|
|
use pgBackRestTest::Common::DbVersion;
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
use pgBackRestTest::Common::HostGroupTest;
|
|
use pgBackRestTest::Common::RunTest;
|
|
use pgBackRestTest::Common::StorageRepo;
|
|
use pgBackRestTest::Common::Wait;
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
use pgBackRestTest::Env::Host::HostBaseTest;
|
|
use pgBackRestTest::Env::Manifest;
|
|
|
|
####################################################################################################################################
|
|
# Test WAL size
|
|
####################################################################################################################################
|
|
use constant PG_WAL_SIZE_TEST => 16777216;
|
|
|
|
####################################################################################################################################
|
|
# Host defaults
|
|
####################################################################################################################################
|
|
use constant HOST_PATH_SPOOL => 'spool';
|
|
use constant HOST_PATH_DB => 'db';
|
|
use constant HOST_PATH_DB_BASE => 'base';
|
|
|
|
####################################################################################################################################
|
|
# new
|
|
####################################################################################################################################
|
|
sub new
|
|
{
|
|
my $class = shift; # Class name
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$oParam,
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '->new', \@_,
|
|
{name => 'oParam', required => false, trace => true},
|
|
);
|
|
|
|
# Get host group
|
|
my $oHostGroup = hostGroupGet();
|
|
|
|
# Is standby?
|
|
my $bStandby = defined($$oParam{bStandby}) && $$oParam{bStandby} ? true : false;
|
|
|
|
my $self = $class->SUPER::new(
|
|
{
|
|
strName => $bStandby ? HOST_DB_STANDBY : HOST_DB_PRIMARY,
|
|
strImage => $$oParam{strImage},
|
|
bTls => $oParam->{bTls},
|
|
strBackupDestination => $$oParam{strBackupDestination},
|
|
bSynthetic => $$oParam{bSynthetic},
|
|
bRepoLocal => $oParam->{bRepoLocal},
|
|
bRepoEncrypt => $oParam->{bRepoEncrypt},
|
|
});
|
|
bless $self, $class;
|
|
|
|
# Set parameters
|
|
$self->{bStandby} = $bStandby;
|
|
|
|
$self->{strDbPath} = $self->testPath() . '/' . HOST_PATH_DB;
|
|
$self->{strDbBasePath} = $self->dbPath() . '/' . HOST_PATH_DB_BASE;
|
|
$self->{strTablespacePath} = $self->dbPath() . '/tablespace';
|
|
|
|
storageTest()->pathCreate($self->dbBasePath(), {strMode => '0700', bCreateParent => true});
|
|
|
|
$self->{strSpoolPath} = $self->testPath() . '/' . HOST_PATH_SPOOL;
|
|
storageTest()->pathCreate($self->spoolPath());
|
|
|
|
# Initialize linkRemap Hashes
|
|
$self->{hLinkRemap} = {};
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn
|
|
(
|
|
$strOperation,
|
|
{name => 'self', value => $self, trace => true}
|
|
);
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# archivePush
|
|
####################################################################################################################################
|
|
sub archivePush
|
|
{
|
|
my $self = shift;
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$strWalPath,
|
|
$strArchiveTestFile,
|
|
$iArchiveNo,
|
|
$iExpectedError,
|
|
$bAsync,
|
|
$strOptionalParam,
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '->archivePush', \@_,
|
|
{name => 'strWalPath'},
|
|
{name => 'strArchiveTestFile', required => false},
|
|
{name => 'iArchiveNo', required => false},
|
|
{name => 'iExpectedError', required => false},
|
|
{name => 'bAsync', default => true},
|
|
{name => 'strOptionalParam', required => false},
|
|
);
|
|
|
|
my $strSourceFile;
|
|
|
|
if (defined($strArchiveTestFile))
|
|
{
|
|
$strSourceFile = "${strWalPath}/" . uc(sprintf('0000000100000001%08x', $iArchiveNo));
|
|
|
|
storageTest()->copy($strArchiveTestFile, storageTest()->openWrite($strSourceFile, {bPathCreate => true}));
|
|
|
|
storageTest()->pathCreate("${strWalPath}/archive_status/", {bIgnoreExists => true, bCreateParent => true});
|
|
storageTest()->put("${strWalPath}/archive_status/" . uc(sprintf('0000000100000001%08x', $iArchiveNo)) . '.ready');
|
|
}
|
|
|
|
$self->executeSimple(
|
|
$self->backrestExe() .
|
|
' --config=' . $self->backrestConfig() .
|
|
' --log-level-console=warn --archive-push-queue-max=' . int(2 * PG_WAL_SIZE_TEST) .
|
|
' --stanza=' . $self->stanza() .
|
|
($bAsync ? '' : ' --no-archive-async') .
|
|
" archive-push" . (defined($strSourceFile) ? " ${strSourceFile}" : '') .
|
|
(defined($strOptionalParam) ? " ${strOptionalParam}" : ''),
|
|
{iExpectedExitStatus => $iExpectedError, bLogOutput => $self->synthetic()});
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn($strOperation);
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# linkRemap
|
|
####################################################################################################################################
|
|
sub linkRemap
|
|
{
|
|
my $self = shift;
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
my
|
|
(
|
|
$strOperation,
|
|
$strTarget,
|
|
$strDestination
|
|
) =
|
|
logDebugParam
|
|
(
|
|
__PACKAGE__ . '->linkRemap', \@_,
|
|
{name => 'strTarget'},
|
|
{name => 'strDestination'},
|
|
);
|
|
|
|
${$self->{hLinkRemap}}{$strTarget} = $strDestination;
|
|
|
|
# Return from function and log return values if any
|
|
return logDebugReturn($strOperation);
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# Getters
|
|
####################################################################################################################################
|
|
sub dbPath {return shift->{strDbPath};}
|
|
|
|
sub dbBasePath
|
|
{
|
|
my $self = shift;
|
|
my $iIndex = shift;
|
|
|
|
return $self->{strDbBasePath} . (defined($iIndex) ? "-${iIndex}" : '');
|
|
}
|
|
|
|
sub spoolPath {return shift->{strSpoolPath}}
|
|
sub standby {return shift->{bStandby}}
|
|
|
|
sub tablespacePath
|
|
{
|
|
my $self = shift;
|
|
my $iTablespace = shift;
|
|
my $iIndex = shift;
|
|
|
|
return
|
|
$self->{strTablespacePath} .
|
|
(defined($iTablespace) ? "/ts${iTablespace}" .
|
|
(defined($iIndex) ? "-${iIndex}" : '') : '');
|
|
}
|
|
|
|
1;
|