mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Various improvements to the test suite:
* Allow logging to be suppressed via logDisable() and logEnable(). * Added more flexibility in initializing and cleaning up after modules and tests. * testResult() suppresses logging and reports exceptions. * testException() allows messages to be matched with regular expressions. * Refactor name/locations of common modules that setup test environments.
This commit is contained in:
parent
e876a222fc
commit
18db178ac3
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,6 +6,7 @@ test/.vagrant
|
||||
test/package
|
||||
test/nytprof.out
|
||||
test/nytprof/*
|
||||
test/scratch.txt
|
||||
test/coverage*
|
||||
doc/output/*
|
||||
doc/doc/output/*
|
||||
|
@ -232,6 +232,10 @@
|
||||
<release-item>
|
||||
<p>Split the <cmd>check</cmd> command out of the <code>Archive.pm</code> module.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Allow logging to be suppressed via <code>logDisable()</code> and <code>logEnable()</code>.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-core-list>
|
||||
|
||||
@ -262,6 +266,18 @@
|
||||
<release-item>
|
||||
<p>Added unit tests for low-level functions in the <code>File</code> and <code>BackupCommon</code> modules.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Added more flexibility in initializing and cleaning up after modules and tests.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p><code>testResult()</code> suppresses logging and reports exceptions.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p><code>testException()</code> allows messages to be matched with regular expressions.</p>
|
||||
</release-item>
|
||||
</release-feature-list>
|
||||
|
||||
<release-refactor-list>
|
||||
@ -276,6 +292,10 @@
|
||||
<release-item>
|
||||
<p>Added expect log expression to replace year subdirectories in <path>backup.history</path>.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Refactor name/locations of common modules that setup test environments.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-test-list>
|
||||
</release>
|
||||
|
@ -72,6 +72,9 @@ my $strLogLevelFile = OFF;
|
||||
my $strLogLevelConsole = OFF;
|
||||
my $strLogLevelStdErr = WARN;
|
||||
|
||||
# Allow log to be globally enabled or disabled with logEnable() and logDisable()
|
||||
my $bLogDisable = 0;
|
||||
|
||||
# Test globals
|
||||
my $bTest = false;
|
||||
my $fTestDelay;
|
||||
@ -186,6 +189,26 @@ sub logLevelSet
|
||||
|
||||
push @EXPORT, qw(logLevelSet);
|
||||
|
||||
####################################################################################################################################
|
||||
# logDisable
|
||||
####################################################################################################################################
|
||||
sub logDisable
|
||||
{
|
||||
$bLogDisable++;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logDisable);
|
||||
|
||||
####################################################################################################################################
|
||||
# logEnable
|
||||
####################################################################################################################################
|
||||
sub logEnable
|
||||
{
|
||||
$bLogDisable--;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logEnable);
|
||||
|
||||
####################################################################################################################################
|
||||
# logDebugParam
|
||||
#
|
||||
@ -406,6 +429,8 @@ sub logDebugBuild
|
||||
return $rResult;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logDebugBuild);
|
||||
|
||||
####################################################################################################################################
|
||||
# logDebugOut
|
||||
####################################################################################################################################
|
||||
@ -476,6 +501,25 @@ sub logException
|
||||
|
||||
push @EXPORT, qw(logException);
|
||||
|
||||
####################################################################################################################################
|
||||
# logErrorResult
|
||||
####################################################################################################################################
|
||||
sub logErrorResult
|
||||
{
|
||||
my $oResult = shift;
|
||||
my $iCode = shift;
|
||||
my $strMessage = shift;
|
||||
|
||||
if (!$oResult)
|
||||
{
|
||||
confess &log(ERROR, $strMessage . (defined($!) ? ": $!" : ''), $iCode);
|
||||
}
|
||||
|
||||
return $oResult;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(logErrorResult);
|
||||
|
||||
####################################################################################################################################
|
||||
# LOG - log messages
|
||||
####################################################################################################################################
|
||||
@ -575,69 +619,74 @@ sub log
|
||||
(defined($iProcessId) ? $iProcessId : 0)) .
|
||||
(' ' x (7 - length($strLevel))) . "${strLevel}: ${strMessageFormat}\n";
|
||||
|
||||
# Output to stderr depending on log level
|
||||
if (!$rExtra->{bLogConsole} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelStdErr}{rank})
|
||||
# Skip output if disabled
|
||||
if (!$bLogDisable)
|
||||
{
|
||||
if ($strLogLevelStdErr ne PROTOCOL)
|
||||
# Output to stderr depending on log level
|
||||
if (!$rExtra->{bLogConsole} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelStdErr}{rank})
|
||||
{
|
||||
syswrite(*STDERR, $strLevel . (defined($iCode) ? " [${iCode}]" : '') . ': ');
|
||||
if ($strLogLevelStdErr ne PROTOCOL)
|
||||
{
|
||||
syswrite(*STDERR, $strLevel . (defined($iCode) ? " [${iCode}]" : '') . ': ');
|
||||
}
|
||||
|
||||
syswrite(*STDERR, "${strMessage}\n");
|
||||
$rExtra->{bLogConsole} = true;
|
||||
}
|
||||
|
||||
syswrite(*STDERR, "${strMessage}\n");
|
||||
$rExtra->{bLogConsole} = true;
|
||||
}
|
||||
# Else output to stdout depending on log level and test flag
|
||||
elsif (!$rExtra->{bLogConsole} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelConsole}{rank} || $bTest && $strLevel eq TEST)
|
||||
{
|
||||
if (!$bSuppressLog)
|
||||
{
|
||||
syswrite(*STDOUT, $strMessageFormat);
|
||||
}
|
||||
|
||||
# If in test mode and this is a test messsage then delay so the calling process has time to read the message
|
||||
if ($bTest && $strLevel eq TEST && $fTestDelay > 0)
|
||||
{
|
||||
usleep($fTestDelay * 1000000);
|
||||
}
|
||||
|
||||
$rExtra->{bLogConsole} = true;
|
||||
}
|
||||
|
||||
# Output to file depending on log level and test flag
|
||||
if (!$rExtra->{bLogLogFile} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelFile}{rank})
|
||||
{
|
||||
if (defined($hLogFile) || (defined($strLogLevelFile) && $strLogLevelFile ne OFF))
|
||||
# Else output to stdout depending on log level and test flag
|
||||
elsif (!$rExtra->{bLogConsole} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelConsole}{rank} ||
|
||||
$bTest && $strLevel eq TEST)
|
||||
{
|
||||
if (!$bSuppressLog)
|
||||
{
|
||||
if (defined($hLogFile))
|
||||
{
|
||||
syswrite($hLogFile, $strMessageFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
$strLogFileCache .= $strMessageFormat;
|
||||
}
|
||||
syswrite(*STDOUT, $strMessageFormat);
|
||||
}
|
||||
|
||||
if ($strLevel eq ASSERT ||
|
||||
($strLevel eq ERROR && ($strLogLevelFile eq DEBUG || $strLogLevelFile eq TRACE)))
|
||||
{
|
||||
my $strStackTrace = longmess() . "\n";
|
||||
$strStackTrace =~ s/\n/\n /g;
|
||||
# If in test mode and this is a test messsage then delay so the calling process has time to read the message
|
||||
if ($bTest && $strLevel eq TEST && $fTestDelay > 0)
|
||||
{
|
||||
usleep($fTestDelay * 1000000);
|
||||
}
|
||||
|
||||
$rExtra->{bLogConsole} = true;
|
||||
}
|
||||
|
||||
# Output to file depending on log level and test flag
|
||||
if (!$rExtra->{bLogLogFile} && $iLogLevelRank <= $oLogLevelRank{$strLogLevelFile}{rank})
|
||||
{
|
||||
if (defined($hLogFile) || (defined($strLogLevelFile) && $strLogLevelFile ne OFF))
|
||||
{
|
||||
if (!$bSuppressLog)
|
||||
{
|
||||
if (defined($hLogFile))
|
||||
{
|
||||
syswrite($hLogFile, $strStackTrace);
|
||||
syswrite($hLogFile, $strMessageFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
$strLogFileCache .= $strStackTrace;
|
||||
$strLogFileCache .= $strMessageFormat;
|
||||
}
|
||||
|
||||
if ($strLevel eq ASSERT ||
|
||||
($strLevel eq ERROR && ($strLogLevelFile eq DEBUG || $strLogLevelFile eq TRACE)))
|
||||
{
|
||||
my $strStackTrace = longmess() . "\n";
|
||||
$strStackTrace =~ s/\n/\n /g;
|
||||
|
||||
if (defined($hLogFile))
|
||||
{
|
||||
syswrite($hLogFile, $strStackTrace);
|
||||
}
|
||||
else
|
||||
{
|
||||
$strLogFileCache .= $strStackTrace;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rExtra->{bLogFile} = true;
|
||||
$rExtra->{bLogFile} = true;
|
||||
}
|
||||
}
|
||||
|
||||
# Throw a typed exception if code is defined
|
||||
|
@ -84,9 +84,9 @@ db-version="9.4"
|
||||
[db:history]
|
||||
1={"db-id":6353949018581704918,"db-version":"9.4"}
|
||||
|
||||
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-fork --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
P00 INFO: archive-push command begin [BACKREST-VERSION]: --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --no-fork --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=debug --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/repo/log --repo-path=[TEST_PATH]/db-master/repo --stanza=db
|
||||
P00 INFO: archive-push command begin [BACKREST-VERSION]: --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=debug --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/repo/log --repo-path=[TEST_PATH]/db-master/repo --stanza=db
|
||||
P00 INFO: push WAL segment [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
P00 DEBUG: Archive::ArchivePush->push(): bAsync = false, strSourceFile = [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
P00 DEBUG: Protocol::Protocol::protocolGet(): iRemoteIdx = <1>, oParam = [undef], strRemoteType = backup
|
||||
|
@ -84,9 +84,9 @@ db-version="9.4"
|
||||
[db:history]
|
||||
1={"db-id":6353949018581704918,"db-version":"9.4"}
|
||||
|
||||
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-fork --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stanza=db archive-push [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
P00 INFO: archive-push command begin [BACKREST-VERSION]: --backup-cmd=[BACKREST-BIN] --backup-config=[TEST_PATH]/backup/pgbackrest.conf --backup-host=backup --backup-user=[USER-2] --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --no-fork --lock-path=[TEST_PATH]/db-master/spool/lock --log-level-console=debug --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/spool/log --repo-path=[TEST_PATH]/backup/repo --stanza=db
|
||||
P00 INFO: archive-push command begin [BACKREST-VERSION]: --backup-cmd=[BACKREST-BIN] --backup-config=[TEST_PATH]/backup/pgbackrest.conf --backup-host=backup --backup-user=[USER-2] --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/spool/lock --log-level-console=debug --log-level-file=trace --log-level-stderr=off --log-path=[TEST_PATH]/db-master/spool/log --repo-path=[TEST_PATH]/backup/repo --stanza=db
|
||||
P00 INFO: push WAL segment [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
P00 DEBUG: Archive::ArchivePush->push(): bAsync = false, strSourceFile = [TEST_PATH]/db-master/db/base/pg_xlog/000000010000000100000001
|
||||
P00 DEBUG: Protocol::Protocol::protocolGet(): iRemoteIdx = <1>, oParam = [undef], strRemoteType = backup
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ArchiveGetTest.pm - Tests for archive-get command
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Archive::ArchiveGetTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -25,9 +25,9 @@ use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Manifest;
|
||||
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ArchivePushTest.pm - Tests for archive-push command
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Archive::ArchivePushTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -25,9 +25,9 @@ use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Manifest;
|
||||
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# archiveCheck
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ArchiveStopTest.pm - Tests for archive-push command to make sure aync queue limits are implemented correctly
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Archive::ArchiveStopTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -25,9 +25,9 @@ use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Manifest;
|
||||
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ArchiveUnitTest.pm - Tests for ArchiveCommon module
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Archive::ArchiveUnitTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
|
@ -2,7 +2,7 @@
|
||||
# BackupUnitTest.pm - Tests for Backup module
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Backup::BackupUnitTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
|
@ -271,23 +271,23 @@ sub perlInstall
|
||||
if ($strOS eq VM_CO6)
|
||||
{
|
||||
return $strImage .
|
||||
"RUN yum install -y perl perl-Time-HiRes perl-parent perl-JSON perl-Digest-SHA perl-DBD-Pg";
|
||||
'RUN yum install -y perl perl-Time-HiRes perl-parent perl-JSON perl-Digest-SHA perl-DBD-Pg';
|
||||
}
|
||||
elsif ($strOS eq VM_CO7)
|
||||
{
|
||||
return $strImage .
|
||||
"RUN yum install -y perl perl-JSON-PP perl-Digest-SHA perl-DBD-Pg";
|
||||
'RUN yum install -y perl perl-JSON-PP perl-Digest-SHA perl-DBD-Pg';
|
||||
}
|
||||
elsif ($strOS eq VM_U12 || $strOS eq VM_U14)
|
||||
{
|
||||
return $strImage .
|
||||
"RUN apt-get install -y libdbd-pg-perl libdbi-perl libnet-daemon-perl libplrpc-perl";
|
||||
'RUN apt-get install -y libdbd-pg-perl libdbi-perl libnet-daemon-perl libplrpc-perl';
|
||||
}
|
||||
elsif ($strOS eq VM_U16 || $strOS eq VM_D8)
|
||||
{
|
||||
return $strImage .
|
||||
"RUN apt-get install -y libdbd-pg-perl libdbi-perl" .
|
||||
($strOS eq VM_U16 ? ' libdevel-cover-perl' : '');
|
||||
'RUN apt-get install -y libdbd-pg-perl libdbi-perl' .
|
||||
($strOS eq VM_U16 ? ' libdevel-cover-perl libtest-pod-coverage-perl' : '');
|
||||
}
|
||||
|
||||
confess &log(ERROR, "unable to install perl for os '${strOS}'");
|
||||
|
@ -1,8 +1,8 @@
|
||||
####################################################################################################################################
|
||||
# FullCommonTest.pm - Common code for backup tests
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Full::FullCommonTest;
|
||||
use parent 'pgBackRestTest::Common::RunTest';
|
||||
package pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use parent 'pgBackRestTest::Config::ConfigEnvTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -33,9 +33,9 @@ use constant WAL_VERSION_94 => '94';
|
||||
push @EXPORT, qw(WAL_VERSION_94);
|
||||
|
||||
####################################################################################################################################
|
||||
# init
|
||||
# initModule
|
||||
####################################################################################################################################
|
||||
sub init
|
||||
sub initModule
|
||||
{
|
||||
# Set file and path modes
|
||||
pathModeDefaultSet('0700');
|
@ -157,7 +157,8 @@ sub testListGet
|
||||
my $oTestRun =
|
||||
{
|
||||
&TEST_VM => $strTestOS,
|
||||
&TEST_CONTAINER => $$oModule{&TESTDEF_TEST_CONTAINER},
|
||||
&TEST_CONTAINER => defined($oTest->{&TESTDEF_TEST_CONTAINER}) ?
|
||||
$oTest->{&TESTDEF_TEST_CONTAINER} : $oModule->{&TESTDEF_TEST_CONTAINER},
|
||||
&TEST_PGSQL_BIN => $strPgSqlBin,
|
||||
&TEST_PERL_ARCH_PATH => $$oyVm{$strTestOS}{&VMDEF_PERL_ARCH_PATH},
|
||||
&TEST_MODULE => $$oModule{&TESTDEF_MODULE_NAME},
|
||||
|
@ -17,9 +17,11 @@ use File::Basename qw(dirname);
|
||||
|
||||
use pgBackRest::Common::Exception;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::Wait;
|
||||
|
||||
use pgBackRestTest::Common::LogTest;
|
||||
use pgBackRestTest::Common::DefineTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::LogTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# Constant to use when bogus data is required
|
||||
@ -59,18 +61,37 @@ sub new
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# init
|
||||
# initModule
|
||||
#
|
||||
# Empty init sub in case the ancestor class does not delare one.
|
||||
####################################################################################################################################
|
||||
sub init {}
|
||||
sub initModule {}
|
||||
|
||||
####################################################################################################################################
|
||||
# final
|
||||
# initTest
|
||||
#
|
||||
# Empty init sub in case the ancestor class does not delare one.
|
||||
####################################################################################################################################
|
||||
sub initTest {}
|
||||
|
||||
####################################################################################################################################
|
||||
# cleanTest
|
||||
#
|
||||
# Delete all files in test directory.
|
||||
####################################################################################################################################
|
||||
sub cleanTest
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
executeTest('sudo rm -rf ' . $self->testPath() . '/*');
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# cleanModule
|
||||
#
|
||||
# Empty final sub in case the ancestor class does not delare one.
|
||||
####################################################################################################################################
|
||||
sub final {}
|
||||
sub cleanModule {}
|
||||
|
||||
####################################################################################################################################
|
||||
# process
|
||||
@ -126,11 +147,14 @@ sub process
|
||||
{name => 'strGroup'},
|
||||
);
|
||||
|
||||
# Init will only be run on first test, clean/init on subsequent tests
|
||||
$self->{bFirstTest} = true;
|
||||
|
||||
# Init, run, and end the test(s)
|
||||
$self->init();
|
||||
$self->initModule();
|
||||
$self->run();
|
||||
$self->final();
|
||||
$self->end();
|
||||
$self->cleanModule();
|
||||
|
||||
# Make sure the correct number of tests ran
|
||||
my $hModule = testDefModuleGet($self->{strModule});
|
||||
@ -229,6 +253,14 @@ sub begin
|
||||
|
||||
$self->{strBackRestExe} = $strExe;
|
||||
|
||||
if (!$self->{bFirstTest})
|
||||
{
|
||||
$self->cleanTest();
|
||||
}
|
||||
|
||||
$self->initTest();
|
||||
$self->{bFirstTest} = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -255,16 +287,60 @@ sub testResult
|
||||
my $self = shift;
|
||||
my $fnSub = shift;
|
||||
my $strExpected = shift;
|
||||
my $strDescription = shift;
|
||||
my $iWaitSeconds = shift;
|
||||
|
||||
my $strActual = $fnSub->();
|
||||
&log(INFO, ' ' . (defined($strDescription) ? $strDescription : 'no description'));
|
||||
my $strActual;
|
||||
|
||||
if (!defined($strExpected) && defined($strActual) || defined($strExpected) && !defined($strActual) ||
|
||||
$strActual ne $strExpected)
|
||||
my $oWait = waitInit(defined($iWaitSeconds) ? $iWaitSeconds : 0);
|
||||
my $bDone = false;
|
||||
|
||||
do
|
||||
{
|
||||
confess
|
||||
'expected ' . (defined($strExpected) ? "\"${strExpected}\"" : '[undef]') .
|
||||
" but actual was " . (defined($strActual) ? "\"${strActual}\"" : '[undef]');
|
||||
}
|
||||
eval
|
||||
{
|
||||
logDisable();
|
||||
my @stryResult = ref($fnSub) eq 'CODE' ? $fnSub->() : $fnSub;
|
||||
|
||||
if (@stryResult <= 1)
|
||||
{
|
||||
$strActual = ${logDebugBuild($stryResult[0])};
|
||||
}
|
||||
else
|
||||
{
|
||||
$strActual = ${logDebugBuild(\@stryResult)};
|
||||
}
|
||||
|
||||
logEnable();
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
logEnable();
|
||||
|
||||
if (!isException($EVAL_ERROR))
|
||||
{
|
||||
confess "unexpected standard Perl exception" . (defined($EVAL_ERROR) ? ": ${EVAL_ERROR}" : '');
|
||||
}
|
||||
|
||||
confess &logException($EVAL_ERROR);
|
||||
};
|
||||
|
||||
if ($strActual ne (defined($strExpected) ? $strExpected : "[undef]"))
|
||||
{
|
||||
if (!waitMore($oWait))
|
||||
{
|
||||
confess
|
||||
'expected ' . (defined($strExpected) ? "\"${strExpected}\"" : '[undef]') .
|
||||
" but actual was " . (defined($strActual) ? "\"${strActual}\"" : '[undef]');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bDone = true;
|
||||
}
|
||||
} while (!$bDone);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
@ -277,22 +353,31 @@ sub testException
|
||||
my $iCodeExpected = shift;
|
||||
my $strMessageExpected = shift;
|
||||
|
||||
# Output first line of the error message
|
||||
my @stryErrorMessage = split('\n', $strMessageExpected);
|
||||
&log(INFO, " [${iCodeExpected}] " . $stryErrorMessage[0]);
|
||||
|
||||
my $bError = false;
|
||||
my $strError = "exception ${iCodeExpected}, \"${strMessageExpected}\" was expected";
|
||||
|
||||
eval
|
||||
{
|
||||
logDisable();
|
||||
$fnSub->();
|
||||
logEnable();
|
||||
return true;
|
||||
}
|
||||
or do
|
||||
{
|
||||
logEnable();
|
||||
|
||||
if (!isException($EVAL_ERROR))
|
||||
{
|
||||
confess "${strError} but actual was standard Perl exception";
|
||||
confess "${strError} but actual was standard Perl exception" . (defined($EVAL_ERROR) ? ": ${EVAL_ERROR}" : '');
|
||||
}
|
||||
|
||||
if (!($EVAL_ERROR->code() == $iCodeExpected && $EVAL_ERROR->message() eq $strMessageExpected))
|
||||
if (!($EVAL_ERROR->code() == $iCodeExpected &&
|
||||
($EVAL_ERROR->message() eq $strMessageExpected || $EVAL_ERROR->message() =~ $strMessageExpected)))
|
||||
{
|
||||
confess "${strError} but actual was " . $EVAL_ERROR->code() . ", \"" . $EVAL_ERROR->message() . "\"";
|
||||
}
|
||||
@ -408,7 +493,13 @@ sub testRunExe
|
||||
if (defined($strTest) && $hTest->{&TESTDEF_TEST_NAME} eq $strTest)
|
||||
{
|
||||
$hTestCoverage =
|
||||
defined($hTest->{&TESTDEF_TEST_COVERAGE}{$iRun}) ? $hTest->{&TESTDEF_TEST_COVERAGE}{$iRun}: $hTestCoverage;
|
||||
defined($hTest->{&TESTDEF_TEST_COVERAGE}{$iRun}) ? $hTest->{&TESTDEF_TEST_COVERAGE}{$iRun} :
|
||||
$hTest->{&TESTDEF_TEST_COVERAGE}{&TESTDEF_TEST_ALL};
|
||||
|
||||
if (!defined($hTestCoverage))
|
||||
{
|
||||
$hTestCoverage = $hTestModule->{&TESTDEF_TEST_COVERAGE};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# ConfigConfigTest.pm - Tests for mixed command line and config file options in Config.pm
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Config::ConfigConfigTest;
|
||||
use parent 'pgBackRestTest::Config::ConfigCommonTest';
|
||||
use parent 'pgBackRestTest::Config::ConfigEnvTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -350,4 +350,10 @@ sub run
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Getters
|
||||
####################################################################################################################################
|
||||
# Change this from the default so the same stanza is not used in all tests.
|
||||
sub stanza {return 'main'};
|
||||
|
||||
1;
|
||||
|
@ -1,7 +1,7 @@
|
||||
####################################################################################################################################
|
||||
# ConfigCommonTest.pm - Common code for Config unit tests
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Config::ConfigCommonTest;
|
||||
package pgBackRestTest::Config::ConfigEnvTest;
|
||||
use parent 'pgBackRestTest::Common::RunTest';
|
||||
|
||||
####################################################################################################################################
|
||||
@ -45,6 +45,16 @@ sub commandSetTest
|
||||
$$oOption{command} = $strCommand;
|
||||
}
|
||||
|
||||
sub optionReset
|
||||
{
|
||||
my $self = shift;
|
||||
my $oOption = shift;
|
||||
my $strKey = shift;
|
||||
|
||||
delete($$oOption{option}{$strKey});
|
||||
delete($$oOption{boolean}{$strKey});
|
||||
}
|
||||
|
||||
# sub optionRemoveTest
|
||||
# {
|
||||
# my $self = shift;
|
||||
@ -236,10 +246,4 @@ sub optionTestExpect
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Getters
|
||||
####################################################################################################################################
|
||||
# Change this from the default so the same stanza is not used in all tests.
|
||||
sub stanza {return 'main'};
|
||||
|
||||
1;
|
@ -2,7 +2,7 @@
|
||||
# ConfigOptionTest.pm - Tests for command line options in Config.pm
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Config::ConfigOptionTest;
|
||||
use parent 'pgBackRestTest::Config::ConfigCommonTest';
|
||||
use parent 'pgBackRestTest::Config::ConfigEnvTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -344,7 +344,7 @@ sub run
|
||||
|
||||
my $strCommand = commandWrite(CMD_ARCHIVE_GET);
|
||||
my $strExpectedCommand = abs_path($0) . " --backup-host=db.mydomain.com \"--db-path=/db path/main\"" .
|
||||
" --repo-path=/repo --stanza=main " . CMD_ARCHIVE_GET;
|
||||
" --repo-path=/repo --stanza=app " . CMD_ARCHIVE_GET;
|
||||
|
||||
if ($strCommand ne $strExpectedCommand)
|
||||
{
|
||||
@ -380,4 +380,10 @@ sub run
|
||||
}
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Getters
|
||||
####################################################################################################################################
|
||||
# Change this from the default so the same stanza is not used in all tests.
|
||||
sub stanza {return 'app'};
|
||||
|
||||
1;
|
||||
|
@ -1,7 +1,7 @@
|
||||
####################################################################################################################################
|
||||
# ExpireCommonTest.pm - Common code for expire tests
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Expire::ExpireCommonTest;
|
||||
package pgBackRestTest::Expire::ExpireEnvTest;
|
||||
use parent 'pgBackRestTest::Common::RunTest';
|
||||
|
||||
####################################################################################################################################
|
@ -2,7 +2,7 @@
|
||||
# ExpireExpireTest.pm - Tests for expire command
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Expire::ExpireExpireTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -25,10 +25,10 @@ use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Manifest;
|
||||
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
use pgBackRestTest::Expire::ExpireCommonTest;
|
||||
use pgBackRestTest::Expire::ExpireEnvTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
@ -43,7 +43,7 @@ sub run
|
||||
my ($oHostDbMaster, $oHostDbStandby, $oHostBackup, $oFile) = $self->setup(true, $self->expect());
|
||||
|
||||
# Create the test object
|
||||
my $oExpireTest = new pgBackRestTest::Expire::ExpireCommonTest($oHostBackup, $self->backrestExe(), $oFile, $self->expect());
|
||||
my $oExpireTest = new pgBackRestTest::Expire::ExpireEnvTest($oHostBackup, $self->backrestExe(), $oFile, $self->expect());
|
||||
|
||||
# ??? This function creates data elements in the $oExpireTest object that are used by the $oExpireTest functions. But
|
||||
# should probably change to use the stanza-create command especially with stanza-upgrade.
|
||||
|
@ -22,11 +22,11 @@ use pgBackRestTest::Common::Host::HostBackupTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# init
|
||||
# initModule
|
||||
#
|
||||
# Common objects and variables used by all tests.
|
||||
####################################################################################################################################
|
||||
sub init
|
||||
sub initModule
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
@ -57,13 +57,12 @@ sub init
|
||||
HOST_PROTOCOL_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
####################################################################################################################################
|
||||
# final
|
||||
# cleanModule
|
||||
#
|
||||
# Close objects created for tests.
|
||||
####################################################################################################################################
|
||||
sub final
|
||||
sub cleanModule
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
|
@ -93,7 +93,7 @@ sub run
|
||||
# Else success
|
||||
else
|
||||
{
|
||||
$self->testResult($strFunction, "0");
|
||||
$self->testResult($strFunction, '[undef]');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# FullRealTest.pm - Tests for all commands against a real database
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Full::FullRealTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -28,10 +28,10 @@ use pgBackRest::Manifest;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::FileTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
use pgBackRestTest::Common::Host::HostBaseTest;
|
||||
use pgBackRestTest::Common::Host::HostBackupTest;
|
||||
use pgBackRestTest::Common::Host::HostDbTest;
|
||||
|
@ -2,7 +2,7 @@
|
||||
# FullSyntheticTest.pm - Tests for all commands that can be run against synthetic data
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Full::FullSyntheticTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -27,10 +27,10 @@ use pgBackRest::Manifest;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::FileTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
use pgBackRestTest::Common::Host::HostBackupTest;
|
||||
|
||||
####################################################################################################################################
|
||||
|
@ -2,7 +2,7 @@
|
||||
# StanzaCreateTest.pm - Tests for stanza-create command
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Stanza::StanzaCreateTest;
|
||||
use parent 'pgBackRestTest::Full::FullCommonTest';
|
||||
use parent 'pgBackRestTest::Common::Env::EnvHostTest';
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
@ -25,9 +25,9 @@ use pgBackRest::File;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Manifest;
|
||||
|
||||
use pgBackRestTest::Common::Env::EnvHostTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::RunTest;
|
||||
use pgBackRestTest::Full::FullCommonTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# run
|
||||
@ -69,7 +69,7 @@ sub run
|
||||
# Generate WAL then push to get valid archive data in the archive directory
|
||||
my ($strArchiveFile, $strSourceFile) = $self->archiveGenerate($oFile, $strXlogPath, 1, 1, WAL_VERSION_94);
|
||||
my $strCommand = $oHostDbMaster->backrestExe() . ' --config=' . $oHostDbMaster->backrestConfig() .
|
||||
' --no-fork --stanza=db archive-push';
|
||||
' --stanza=db archive-push';
|
||||
$oHostDbMaster->executeSimple($strCommand . " ${strSourceFile}", {oLogTest => $self->expect()});
|
||||
|
||||
# With data existing in the archive dir, remove the info file and confirm failure
|
||||
|
Loading…
Reference in New Issue
Block a user