1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Log testing can now be enabled for certain deterministic tests. This works by comparing the generated logs against a previous copy. Currently only enabled for the backup/synthetic tests.

This commit is contained in:
David Steele
2015-05-05 11:08:48 -06:00
parent 1d1c7e47d1
commit 56588f6fdd
12 changed files with 5089 additions and 35 deletions

View File

@@ -865,14 +865,15 @@ sub BackRestTestBackup_BackupBegin
$bTestPoint = defined($bTestPoint) ? $bTestPoint : false;
$fTestDelay = defined($fTestDelay) ? $fTestDelay : 0;
&log(INFO, " ${strType} backup" . (defined($strComment) ? " (${strComment})" : ''));
$strComment = "${strType} backup" . (defined($strComment) ? " (${strComment})" : '');
&log(INFO, " $strComment");
BackRestTestCommon_ExecuteBegin(BackRestTestCommon_CommandMainGet() . ' --config=' .
($bRemote ? BackRestTestCommon_RepoPathGet() : BackRestTestCommon_DbPathGet()) .
"/pg_backrest.conf" . ($bSynthetic ? " --no-start-stop" : '') .
($strType ne 'incr' ? " --type=${strType}" : '') .
" --stanza=${strStanza} backup" . ($bTestPoint ? " --test --test-delay=${fTestDelay}": ''),
$bRemote);
$bRemote, $strComment);
}
####################################################################################################################################
@@ -925,7 +926,8 @@ sub BackRestTestBackup_BackupSynthetic
my $fTestDelay = shift;
my $iExpectedExitStatus = shift;
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, true, defined($strTestPoint), $fTestDelay);
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, $strComment, true, defined($strTestPoint), $fTestDelay,
$strComment);
if (defined($strTestPoint))
{
@@ -1177,18 +1179,20 @@ sub BackRestTestBackup_Restore
my $bSynthetic = defined($oExpectedManifestRef) ? true : false;
&log(INFO, ' restore' .
($bDelta ? ' delta' : '') .
($bForce ? ', force' : '') .
($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') .
($strType ? ", type '${strType}'" : '') .
($strTarget ? ", target '${strTarget}'" : '') .
($strTargetTimeline ? ", timeline '${strTargetTimeline}'" : '') .
(defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') .
(defined($bTargetResume) && $bTargetResume ? ', resume' : '') .
(defined($oRemapHashRef) ? ', remap' : '') .
(defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') .
(defined($strComment) ? " (${strComment})" : ''));
$strComment = 'restore' .
($bDelta ? ' delta' : '') .
($bForce ? ', force' : '') .
($strBackup ne 'latest' ? ", backup '${strBackup}'" : '') .
($strType ? ", type '${strType}'" : '') .
($strTarget ? ", target '${strTarget}'" : '') .
($strTargetTimeline ? ", timeline '${strTargetTimeline}'" : '') .
(defined($bTargetExclusive) && $bTargetExclusive ? ', exclusive' : '') .
(defined($bTargetResume) && $bTargetResume ? ', resume' : '') .
(defined($oRemapHashRef) ? ', remap' : '') .
(defined($iExpectedExitStatus) ? ", expect exit ${iExpectedExitStatus}" : '') .
(defined($strComment) ? " (${strComment})" : '');
&log(INFO, " ${strComment}");
if (!defined($oExpectedManifestRef))
{
@@ -1231,7 +1235,7 @@ sub BackRestTestBackup_Restore
(defined($bTargetExclusive) && $bTargetExclusive ? " --target-exclusive" : '') .
(defined($bTargetResume) && $bTargetResume ? " --target-resume" : '') .
" --stanza=${strStanza} restore",
undef, undef, undef, $iExpectedExitStatus);
undef, undef, undef, $iExpectedExitStatus, $strComment);
if (!defined($iExpectedExitStatus))
{
@@ -1424,6 +1428,8 @@ sub BackRestTestBackup_Test
# Setup test variables
my $iRun;
my $strModule = 'backup';
my $strThisTest;
my $bCreate;
my $strStanza = BackRestTestCommon_StanzaGet();
@@ -1865,15 +1871,17 @@ sub BackRestTestBackup_Test
}
#-------------------------------------------------------------------------------------------------------------------------------
# Test backup
# Test synthetic
#
# Check the backup and restore functionality using synthetic data.
#-------------------------------------------------------------------------------------------------------------------------------
if ($strTest eq 'all' || $strTest eq 'backup')
$strThisTest = 'synthetic';
if ($strTest eq 'all' || $strTest eq $strThisTest)
{
$iRun = 0;
&log(INFO, "Test Backup\n");
&log(INFO, "Test ${strModule} - ${strThisTest}\n");
for (my $bRemote = false; $bRemote <= true; $bRemote++)
{
@@ -1883,7 +1891,8 @@ sub BackRestTestBackup_Test
{
# Increment the run, log, and decide whether this unit test should be run
if (!BackRestTestCommon_Run(++$iRun,
"rmt ${bRemote}, cmp ${bCompress}, hardlink ${bHardlink}")) {next}
"rmt ${bRemote}, cmp ${bCompress}, hardlink ${bHardlink}",
$strModule, $strThisTest)) {next}
# Get base time
my $lTime = time() - 100000;

View File

@@ -51,6 +51,7 @@ my $strCommonHost;
my $strCommonUser;
my $strCommonGroup;
my $strCommonUserBackRest;
my $strCommonBasePath;
my $strCommonTestPath;
my $strCommonDataPath;
my $strCommonRepoPath;
@@ -60,18 +61,27 @@ my $strCommonDbCommonPath;
my $strCommonDbTablespacePath;
my $iCommonDbPort;
my $strCommonDbVersion;
my $iModuleTestRun;
my $iModuleTestRunOnly;
my $bDryRun;
my $bNoCleanup;
my $bLogForce;
# Execution globals
my $strErrorLog;
my $hError;
my $strOutLog;
my $strFullLog;
my $bFullLog = false;
my $hOut;
my $pId;
my $strCommand;
# Test globals
my $strTestLog;
my $strModule;
my $strModuleTest;
my $iModuleTestRun;
####################################################################################################################################
# BackRestTestCommon_ClusterStop
####################################################################################################################################
@@ -158,19 +168,32 @@ sub BackRestTestCommon_Run
{
my $iRun = shift;
my $strLog = shift;
my $strModuleParam = shift;
my $strModuleTestParam = shift;
if (defined($iModuleTestRun) && $iModuleTestRun != $iRun)
# &log(INFO, "module " . (defined($strModule) ? $strModule : ''));
BackRestTestCommon_TestLog();
if (defined($iModuleTestRunOnly) && $iModuleTestRunOnly != $iRun)
{
return false;
}
&log(INFO, 'run ' . sprintf('%03d', $iRun) . ' - ' . $strLog);
$strTestLog = 'run ' . sprintf('%03d', $iRun) . ' - ' . $strLog;
&log(INFO, $strTestLog);
if ($bDryRun)
{
return false;
}
$strFullLog = "${strTestLog}\n" . ('=' x length($strTestLog)) . "\n";
$strModule = $strModuleParam;
$strModuleTest = $strModuleTestParam;
$iModuleTestRun = $iRun;
return true;
}
@@ -179,9 +202,50 @@ sub BackRestTestCommon_Run
####################################################################################################################################
sub BackRestTestCommon_Cleanup
{
BackRestTestCommon_TestLog();
return !$bNoCleanup && !$bDryRun;
}
####################################################################################################################################
# BackRestTestCommon_TestLog
####################################################################################################################################
sub BackRestTestCommon_TestLog
{
if (defined($strModule))
{
my $hFile;
my $strLogFile = BackRestTestCommon_BasePathGet() .
sprintf("/test/log/${strModule}-${strModuleTest}-%03d.log", $iModuleTestRun);
if (!$bLogForce && -e $strLogFile)
{
mkdir(BackRestTestCommon_TestPathGet() . '/log');
my $strTestLogFile = BackRestTestCommon_TestPathGet() .
sprintf("/log/${strModule}-${strModuleTest}-%03d.log", $iModuleTestRun);
open($hFile, '>', $strTestLogFile)
or die "Could not open file '${strTestLogFile}': $!";
print $hFile $strFullLog;
close $hFile;
BackRestTestCommon_Execute("diff ${strLogFile} ${strTestLogFile}");
}
else
{
open($hFile, '>', $strLogFile)
or die "Could not open file '${strLogFile}': $!";
print $hFile $strFullLog;
close $hFile;
}
undef($strModule);
}
}
####################################################################################################################################
# BackRestTestCommon_ExecuteBegin
####################################################################################################################################
@@ -189,6 +253,7 @@ sub BackRestTestCommon_ExecuteBegin
{
my $strCommandParam = shift;
my $bRemote = shift;
my $strComment = shift;
# Set defaults
$bRemote = defined($bRemote) ? $bRemote : false;
@@ -207,6 +272,31 @@ sub BackRestTestCommon_ExecuteBegin
$strOutLog = '';
$hOut = undef;
my $strBinPath = dirname(dirname(abs_path($0))) . '/bin';
$bFullLog = false;
if ($strCommandParam =~ /^$strBinPath\/pg_backrest\.pl/)
{
my $strTestPath = BackRestTestCommon_TestPathGet();
$strCommandParam =~ s/$strBinPath/[BACKREST_BIN_PATH]/g;
$strCommandParam =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/;
if (defined($strTestPath))
{
$strCommandParam =~ s/$strTestPath/[TEST_PATH]/g;
}
if (defined($strComment))
{
$strComment =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/;
$strFullLog .= "\n${strComment}";
}
$strFullLog .= "\n> ${strCommandParam}\n" . ('-' x '132') . "\n";
$bFullLog = true;
}
&log(DEBUG, "executing command: ${strCommand}");
# Execute the command
@@ -227,6 +317,10 @@ sub BackRestTestCommon_ExecuteEnd
$bSuppressError = defined($bSuppressError) ? $bSuppressError : false;
$bShowOutput = defined($bShowOutput) ? $bShowOutput : false;
# Get test path
my $strTestPath = BackRestTestCommon_TestPathGet();
my $strVersion = version_get();
# Create select objects
my $oErrorSelect = IO::Select->new();
$oErrorSelect->add($hError);
@@ -257,6 +351,26 @@ sub BackRestTestCommon_ExecuteEnd
&log(DEBUG, "Found test ${strTest}");
return true;
}
if ($bFullLog)
{
$strLine =~ s/^[^ ]* [^ ]* [^ ]* //;
$strLine =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/g;
$strLine =~ s/version = $strVersion/version = [VERSION]/g;
$strLine =~ s/modification_time = [0-9]+/modification_time = [MODIFICATION_TIME]/g;
$strLine =~ s/user = [^ \n,\[\]]+/user = [USER]/g;
$strLine =~ s/group = [^ \n,\[\]]+/group = [GROUP]/g;
if (defined($strTestPath))
{
$strLine =~ s/$strTestPath/[TEST_PATH]/g;
}
if ($strLine !~ /^ TEST/)
{
$strFullLog .= $strLine;
}
}
}
}
}
@@ -310,8 +424,9 @@ sub BackRestTestCommon_Execute
my $bSuppressError = shift;
my $bShowOutput = shift;
my $iExpectedExitStatus = shift;
my $strComment = shift;
BackRestTestCommon_ExecuteBegin($strCommand, $bRemote);
BackRestTestCommon_ExecuteBegin($strCommand, $bRemote, $strComment);
return BackRestTestCommon_ExecuteEnd(undef, $bSuppressError, $bShowOutput, $iExpectedExitStatus);
}
@@ -463,11 +578,12 @@ sub BackRestTestCommon_Setup
{
my $strTestPathParam = shift;
my $strPgSqlBinParam = shift;
my $iModuleTestRunParam = shift;
my $iModuleTestRunOnlyParam = shift;
my $bDryRunParam = shift;
my $bNoCleanupParam = shift;
my $bLogForceParam = shift;
my $strBasePath = dirname(dirname(abs_path($0)));
$strCommonBasePath = dirname(dirname(abs_path($0)));
$strPgSqlBin = $strPgSqlBinParam;
@@ -483,24 +599,25 @@ sub BackRestTestCommon_Setup
}
else
{
$strCommonTestPath = "${strBasePath}/test/test";
$strCommonTestPath = "${strCommonBasePath}/test/test";
}
$strCommonDataPath = "${strBasePath}/test/data";
$strCommonDataPath = "${strCommonBasePath}/test/data";
$strCommonRepoPath = "${strCommonTestPath}/backrest";
$strCommonLocalPath = "${strCommonTestPath}/local";
$strCommonDbPath = "${strCommonTestPath}/db";
$strCommonDbCommonPath = "${strCommonTestPath}/db/common";
$strCommonDbTablespacePath = "${strCommonTestPath}/db/tablespace";
$strCommonCommandMain = "${strBasePath}/bin/pg_backrest.pl";
$strCommonCommandRemote = "${strBasePath}/bin/pg_backrest_remote.pl";
$strCommonCommandMain = "${strCommonBasePath}/bin/pg_backrest.pl";
$strCommonCommandRemote = "${strCommonBasePath}/bin/pg_backrest_remote.pl";
$strCommonCommandPsql = "${strPgSqlBin}/psql -X %option% -h ${strCommonDbPath}";
$iCommonDbPort = 6543;
$iModuleTestRun = $iModuleTestRunParam;
$iModuleTestRunOnly = $iModuleTestRunOnlyParam;
$bDryRun = $bDryRunParam;
$bNoCleanup = $bNoCleanupParam;
$bLogForce = $bLogForceParam;
BackRestTestCommon_Execute($strPgSqlBin . '/postgres --version');
@@ -853,6 +970,11 @@ sub BackRestTestCommon_UserBackRestGet
return $strCommonUserBackRest;
}
sub BackRestTestCommon_BasePathGet
{
return $strCommonBasePath;
}
sub BackRestTestCommon_TestPathGet
{
return $strCommonTestPath;