From 9d9dae418bc03a4586bdb579d113a651927c4d1a Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 15 Jul 2014 22:32:41 -0400 Subject: [PATCH] Added archive-put unit tests. Lots of other unit test improvements. --- README.md | 4 +- bin/pg_backrest.pl | 7 +- test/lib/BackRestTest/BackupTest.pm | 329 +++++++++++++++------------- test/lib/BackRestTest/CommonTest.pm | 98 +++++++-- test/lib/BackRestTest/FileTest.pm | 132 ++++------- test/test.pl | 23 +- 6 files changed, 314 insertions(+), 279 deletions(-) diff --git a/README.md b/README.md index 9cbd1e7cd..144e338a5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Simple Postgres Backup and Restore * Database restore. -* --version param (with VERSION file written to directory). +* --version param (with with version written into backup.manifest). * Threading for archive-get and archive-put. @@ -30,6 +30,8 @@ Simple Postgres Backup and Restore * Able to set timeout on ssh connection in config file. +* File->wait() function. Waits for a file or directory to exist with configurable retry and timeout. + ## required perl modules * IPC::Run diff --git a/bin/pg_backrest.pl b/bin/pg_backrest.pl index 950799c02..98a9d9ff6 100755 --- a/bin/pg_backrest.pl +++ b/bin/pg_backrest.pl @@ -289,6 +289,9 @@ if ($strOperation eq OP_ARCHIVE_PUSH) my $strSection = $bArchiveLocal ? CONFIG_SECTION_ARCHIVE : CONFIG_SECTION_BACKUP; my $strArchivePath = config_load($strSection, CONFIG_KEY_PATH); + # Get checksum flag + my $bChecksum = config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_CHECKSUM, true, "y") eq "y" ? true : false; + # Get the async compress flag. If compress_async=y then compression is off for the initial push when archiving locally my $bCompressAsync = false; @@ -321,9 +324,6 @@ if ($strOperation eq OP_ARCHIVE_PUSH) # Get the compress flag my $bCompress = $bCompressAsync ? false : config_load($strSection, CONFIG_KEY_COMPRESS, true, "y") eq "y" ? true : false; - # Get the checksum flag - my $bChecksum = config_load($strSection, CONFIG_KEY_CHECKSUM, true, "y") eq "y" ? true : false; - # Create the file object my $oFile = BackRest::File->new ( @@ -391,7 +391,6 @@ if ($strOperation eq OP_ARCHIVE_PUSH) # Get the new operational flags my $bCompress = config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_COMPRESS, true, "y") eq "y" ? true : false; - my $bChecksum = config_load(CONFIG_SECTION_BACKUP, CONFIG_KEY_CHECKSUM, true, "y") eq "y" ? true : false; my $iArchiveMaxMB = config_load(CONFIG_SECTION_ARCHIVE, CONFIG_KEY_ARCHIVE_MAX_MB); # eval diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index 91c2d45b9..ef189ec10 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -13,6 +13,7 @@ use english; use Carp; use File::Basename; +use File::Copy "cp"; use lib dirname($0) . "/../lib"; use BackRest::Utility; @@ -147,7 +148,6 @@ sub BackRestTestBackup_Create sub BackRestTestBackup_Test { my $strTest = shift; - my $iTestRun = shift; # If no test was specified, then run them all if (!defined($strTest)) @@ -157,9 +157,10 @@ sub BackRestTestBackup_Test # Setup test variables my $iRun; + my $bCreate; $strTestPath = BackRestTestCommon_TestPathGet(); my $strStanza = BackRestTestCommon_StanzaGet(); - my $strUser = BackRestTestCommon_UserGet(); + my $strUserBackRest = BackRestTestCommon_UserBackRestGet(); my $strGroup = BackRestTestCommon_GroupGet(); $strHost = BackRestTestCommon_HostGet(); $strUserBackRest = BackRestTestCommon_UserBackRestGet(); @@ -167,31 +168,153 @@ sub BackRestTestBackup_Test # Print test banner &log(INFO, "BACKUP MODULE ******************************************************************"); - if ($strTest eq 'all' || $strTest eq 'archive') + #------------------------------------------------------------------------------------------------------------------------------- + # Create remote + #------------------------------------------------------------------------------------------------------------------------------- + my $oRemote = BackRest::Remote->new + ( + strHost => $strHost, + strUser => $strUserBackRest, + strCommand => BackRestTestCommon_CommandRemoteGet() + ); + + #------------------------------------------------------------------------------------------------------------------------------- + # Test archive + #------------------------------------------------------------------------------------------------------------------------------- + if ($strTest eq 'all' || $strTest eq 'archive-push') { $iRun = 0; + $bCreate = true; + my $strXlogPath = BackRestTestCommon_DbCommonPathGet() . '/pg_xlog'; + my $strArchiveChecksum = '1c7e00fd09b9dd11fc2966590b3e3274645dd031'; + my $iArchiveMax = 3; + my $oFile; - &log(INFO, "Test Full Backup\n"); + &log(INFO, "Test Archiving\n"); for (my $bRemote = false; $bRemote <= true; $bRemote++) { - BackRestTestBackup_Create($bRemote, false); - - for (my $bArchiveLocal = false; $bArchiveLocal <= $bRemote; $bArchiveLocal++) + for (my $bCompress = false; $bCompress <= true; $bCompress++) { - $iRun++; + for (my $bChecksum = false; $bChecksum <= true; $bChecksum++) + { + for (my $bArchiveAsync = false; $bArchiveAsync <= $bRemote; $bArchiveAsync++) + { + for (my $bCompressAsync = false; $bCompressAsync <= true; $bCompressAsync++) + { + # Increment the run, log, and decide whether this unit test should be run + if (!BackRestTestCommon_Run(++$iRun, + "rmt ${bRemote}, cmp ${bCompress}, chk ${bChecksum}, " . + "arc_async ${bArchiveAsync}, cmp_async ${bCompressAsync}")) {next} - # &log(INFO, "run ${iRun} - " . - # "remote ${bRemote}, archive_local ${bArchiveLocal}, full ${iFull}"); + # Create the test directory + if ($bCreate) + { + # Create the file object + $oFile = (BackRest::File->new + ( + strStanza => $strStanza, + strBackupPath => BackRestTestCommon_BackupPathGet(), + strRemote => $bRemote ? 'backup' : undef, + oRemote => $bRemote ? $oRemote : undef + ))->clone(); + + BackRestTestBackup_Create($bRemote, false); + + # Create the db/common/pg_xlog directory + mkdir($strXlogPath) + or confess 'Unable to create ${strXlogPath} path'; + + $bCreate = false; + } + + BackRestTestCommon_ConfigCreate('db', + ($bRemote ? REMOTE_BACKUP : undef), + $bCompress, + $bChecksum, # checksum + undef, # hardlink + undef, # thread-max + $bArchiveAsync, + $bCompressAsync); + + my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_DbPathGet() . + "/pg_backrest.conf --stanza=db archive-push"; + + + # Loop through backups + for (my $iBackup = 1; $iBackup <= 3; $iBackup++) + { + my $strArchiveFile; + + # Loop through archive files + for (my $iArchive = 1; $iArchive <= $iArchiveMax; $iArchive++) + { + # Construct the archive filename + my $iArchiveNo = (($iBackup - 1) * $iArchiveMax + ($iArchive - 1)) + 1; + + if ($iArchiveNo > 255) + { + confess "backup total * archive total cannot be greater than 255"; + } + + $strArchiveFile = uc(sprintf("0000000100000001%08x", $iArchiveNo)); + + &log(INFO, " backup " . sprintf("%02d", $iBackup) . + ", archive " .sprintf("%02x", $iArchive) . + " - ${strArchiveFile}"); + + cp(BackRestTestCommon_DataPathGet() . '/test.archive.bin', "${strXlogPath}/${strArchiveFile}"); + + BackRestTestCommon_Execute($strCommand . " ${strXlogPath}/${strArchiveFile}"); + + # Build the archive name to check for at the destination + my $strArchiveCheck = $strArchiveFile; + + if ($bChecksum) + { + $strArchiveCheck .= "-${strArchiveChecksum}"; + } + + if ($bCompress) + { + $strArchiveCheck .= ".gz"; + } + + if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck)) + { + sleep(1); + + if (!$oFile->exists(PATH_BACKUP_ARCHIVE, $strArchiveCheck)) + { + confess "unable to find " . $oFile->path_get(PATH_BACKUP_ARCHIVE, $strArchiveCheck); + } + } + } + + # !!! Need to put in tests for .backup files here + } + } + } + } } -# BackRestTestBackup_Drop(); + $bCreate = true; + } + + if (BackRestTestCommon_Cleanup()) + { + &log(INFO, 'cleanup'); + BackRestTestBackup_Drop(); } } + #------------------------------------------------------------------------------------------------------------------------------- + # Test full + #------------------------------------------------------------------------------------------------------------------------------- if ($strTest eq 'all' || $strTest eq 'full') { $iRun = 0; + $bCreate = true; &log(INFO, "Test Full Backup\n"); @@ -199,37 +322,47 @@ sub BackRestTestBackup_Test { for (my $bLarge = false; $bLarge <= false; $bLarge++) { - BackRestTestBackup_Create($bRemote); - - for (my $bArchiveLocal = false; $bArchiveLocal <= $bRemote; $bArchiveLocal++) + for (my $bArchiveAsync = false; $bArchiveAsync <= $bRemote; $bArchiveAsync++) { for (my $bHardlink = false; $bHardlink <= true; $bHardlink++) { - my %oDbConfigHash; - my %oBackupConfigHash; + # Increment the run, log, and decide whether this unit test should be run + if (!BackRestTestCommon_Run(++$iRun, + "rmt ${bRemote}, lrg ${bLarge}, arc_async ${bArchiveAsync}, " . + "hardlink ${bHardlink}")) {next} - # Confgure hard-linking - if ($bHardlink) + # Create the test directory + if ($bCreate) { - $oBackupConfigHash{'global:backup'}{hardlink} = 'y'; + BackRestTestBackup_Create($bRemote); + $bCreate = false; } - # if (!$bArchiveLocal) - # { - # next; - # } - + # Create db config BackRestTestCommon_ConfigCreate('db', - ($bRemote ? REMOTE_BACKUP : undef), $bArchiveLocal, \%oDbConfigHash); + ($bRemote ? REMOTE_BACKUP : undef), + undef, # compress + undef, # checksum + undef, # hardlink + undef, # thread-max + $bArchiveAsync, # archive-async + undef # compressasync + ); + + # Create backup config BackRestTestCommon_ConfigCreate('backup', - ($bRemote ? REMOTE_DB : undef), $bArchiveLocal, \%oBackupConfigHash); + ($bRemote ? REMOTE_DB : undef), + undef, # compress + undef, # checksum + $bHardlink, # hardlink + 8, # thread-max + undef, # archive-async + undef, # compress-async + ); for (my $iFull = 1; $iFull <= 1; $iFull++) { - $iRun++; - - &log(INFO, "run ${iRun} - " . - "remote ${bRemote}, large ${bLarge}, archive_local ${bArchiveLocal}, full ${iFull}"); + &log(INFO, " full " . sprintf("%02d", $iFull)); my $strCommand = BackRestTestCommon_CommandMainGet() . ' --config=' . BackRestTestCommon_BackupPathGet() . "/pg_backrest.conf --type=incr --stanza=${strStanza} backup"; @@ -241,9 +374,7 @@ sub BackRestTestBackup_Test { $iRun++; - &log(INFO, "run ${iRun} - " . - "remote ${bRemote}, large ${bLarge}, archive_local ${bArchiveLocal}, hardlink ${bHardlink}, " . - "full ${iFull}, incr ${iIncr}"); + &log(INFO, " incr " . sprintf("%02d", $iIncr)); BackRestTestCommon_Execute($strCommand, $bRemote); } @@ -251,134 +382,16 @@ sub BackRestTestBackup_Test } } + $bCreate = true; + } + } + + if (BackRestTestCommon_Cleanup()) + { + &log(INFO, 'cleanup'); BackRestTestBackup_Drop(); } - } } - - #------------------------------------------------------------------------------------------------------------------------------- - # Test path_create() - #------------------------------------------------------------------------------------------------------------------------------- - # if ($strTest eq 'all' || $strTest eq 'path_create') - # { - # $iRun = 0; - # - # &log(INFO, "Test File->path_create()\n"); - # - # # Loop through local/remote - # for (my $bRemote = 0; $bRemote <= 1; $bRemote++) - # { - # # Create the file object - # my $oFile = (BackRest::File->new - # ( - # strStanza => $strStanza, - # strBackupPath => $strTestPath, - # strRemote => $bRemote ? 'backup' : undef, - # oRemote => $bRemote ? $oRemote : undef - # ))->clone(); - # - # # Loop through exists (does the paren path exist?) - # for (my $bExists = 0; $bExists <= 1; $bExists++) - # { - # # Loop through exists (does the paren path exist?) - # for (my $bError = 0; $bError <= 1; $bError++) - # { - # # Loop through permission (permission will be set on true) - # for (my $bPermission = 0; $bPermission <= $bExists; $bPermission++) - # { - # my $strPathType = PATH_BACKUP_CLUSTER; - # - # $iRun++; - # - # if (defined($iTestRun) && $iTestRun != $iRun) - # { - # next; - # } - # - # &log(INFO, "run ${iRun} - " . - # "remote ${bRemote}, exists ${bExists}, error ${bError}, permission ${bPermission}"); - # - # # Setup test directory - # BackRestTestFile_Setup($bError); - # - # mkdir("$strTestPath/backup") or confess "Unable to create test/backup directory"; - # mkdir("$strTestPath/backup/db") or confess "Unable to create test/backup/db directory"; - # - # my $strPath = "path"; - # my $strPermission; - # - # # If permission then set one (other than the default) - # if ($bPermission) - # { - # $strPermission = "0700"; - # } - # - # # If not exists then set the path to something bogus - # if ($bError) - # { - # $strPath = "${strTestPath}/private/path"; - # $strPathType = PATH_BACKUP_ABSOLUTE; - # } - # elsif (!$bExists) - # { - # $strPath = "error/path"; - # } - # - # # Execute in eval to catch errors - # my $bErrorExpected = !$bExists || $bError; - # - # eval - # { - # $oFile->path_create($strPathType, $strPath, $strPermission); - # }; - # - # # Check for errors - # if ($@) - # { - # # Ignore errors if the path did not exist - # if ($bErrorExpected) - # { - # next; - # } - # - # confess "error raised: " . $@ . "\n"; - # } - # - # if ($bErrorExpected) - # { - # confess 'error was expected'; - # } - # - # # Make sure the path was actually created - # my $strPathCheck = $oFile->path_get($strPathType, $strPath); - # - # unless (-e $strPathCheck) - # { - # confess "path was not created"; - # } - # - # # Check that the permissions were set correctly - # my $oStat = lstat($strPathCheck); - # - # if (!defined($oStat)) - # { - # confess "unable to stat ${strPathCheck}"; - # } - # - # if ($bPermission) - # { - # if ($strPermission ne sprintf("%04o", S_IMODE($oStat->mode))) - # { - # confess "permissions were not set to {$strPermission}"; - # } - # } - # } - # } - # } - # } - # } - -# BackRestTestBackup_Setup(true); } 1; diff --git a/test/lib/BackRestTest/CommonTest.pm b/test/lib/BackRestTest/CommonTest.pm index 84f2464e4..5cf44fc00 100755 --- a/test/lib/BackRestTest/CommonTest.pm +++ b/test/lib/BackRestTest/CommonTest.pm @@ -23,7 +23,7 @@ use BackRest::File; use Exporter qw(import); our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest - BackRestTestCommon_ConfigCreate + BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_GroupGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet BackRestTestCommon_DataPathGet @@ -45,6 +45,40 @@ my $strCommonArchivePath; my $strCommonDbPath; my $strCommonDbCommonPath; my $iCommonDbPort; +my $iModuleTestRun; +my $bDryRun; +my $bNoCleanup; + +#################################################################################################################################### +# BackRestTestBackup_Run +#################################################################################################################################### +sub BackRestTestCommon_Run +{ + my $iRun = shift; + my $strLog = shift; + + if (defined($iModuleTestRun) && $iModuleTestRun != $iRun) + { + return false; + } + + &log(INFO, "run " . sprintf("%03d", $iRun) . " - " . $strLog); + + if ($bDryRun) + { + return false; + } + + return true; +} + +#################################################################################################################################### +# BackRestTestBackup_Cleanup +#################################################################################################################################### +sub BackRestTestCommon_Cleanup +{ + return !$bNoCleanup && !$bDryRun; +} #################################################################################################################################### # BackRestTestBackup_Execute @@ -68,7 +102,7 @@ sub BackRestTestCommon_Execute my $strError; my $hError; open($hError, '>', \$strError) or confess "unable to open handle to stderr string: $!\n"; - # # + my $strOut; my $hOut; open($hOut, '>', \$strOut) or confess "unable to open handle to stdout string: $!\n"; @@ -103,6 +137,10 @@ sub BackRestTestCommon_Execute #################################################################################################################################### sub BackRestTestCommon_Setup { + my $iModuleTestRunParam = shift; + my $bDryRunParam = shift; + my $bNoCleanupParam = shift; + $strCommonStanza = "db"; $strCommonCommandMain = '/Users/dsteele/pg_backrest/bin/pg_backrest.pl'; $strCommonCommandRemote = '/Users/dsteele/pg_backrest/bin/pg_backrest_remote.pl'; @@ -118,6 +156,9 @@ sub BackRestTestCommon_Setup $strCommonDbPath = "${strCommonTestPath}/db"; $strCommonDbCommonPath = "${strCommonTestPath}/db/common"; $iCommonDbPort = 6543; + $iModuleTestRun = $iModuleTestRunParam; + $bDryRun = $bDryRunParam; + $bNoCleanup = $bNoCleanupParam; } #################################################################################################################################### @@ -127,8 +168,13 @@ sub BackRestTestCommon_ConfigCreate { my $strLocal = shift; my $strRemote = shift; + my $bCompress = shift; + my $bChecksum = shift; + my $bHardlink = shift; + my $iThreadMax = shift; my $bArchiveLocal = shift; - my $oParamHashRef = shift; + my $bCompressAsync = shift; +# my $oParamHashRef = shift; my %oParamHash; tie %oParamHash, 'Config::IniFiles'; @@ -151,36 +197,58 @@ sub BackRestTestCommon_ConfigCreate { $oParamHash{'db:command:option'}{'psql'} = "--port=${iCommonDbPort}"; $oParamHash{'global:log'}{'level-console'} = 'error'; + + if (defined($bHardlink) && $bHardlink) + { + $oParamHash{'global:backup'}{'hardlink'} = 'y'; + } } elsif ($strLocal eq REMOTE_DB) { $oParamHash{'global:log'}{'level-console'} = 'trace'; -# $oParamHash{'global:backup'}{compress} = 'n'; + + if ($bArchiveLocal) + { + $oParamHash{'global:archive'}{path} = BackRestTestCommon_ArchivePathGet(); + + if (!$bCompressAsync) + { + $oParamHash{'global:archive'}{'compress_async'} = 'n'; + } + } } else { confess "invalid local type ${strLocal}"; } - if ($bArchiveLocal) + if (defined($bCompress) && !$bCompress) { - $oParamHash{'global:archive'}{path} = BackRestTestCommon_ArchivePathGet(); -# $oParamHash{'global:archive'}{compress} = 'n'; + $oParamHash{'global:backup'}{'compress'} = 'n'; + } + + if (defined($bChecksum) && !$bChecksum) + { + $oParamHash{'global:backup'}{'checksum'} = 'n'; } $oParamHash{$strCommonStanza}{'path'} = $strCommonDbCommonPath; $oParamHash{'global:backup'}{'path'} = $strCommonBackupPath; - $oParamHash{'global:backup'}{'thread-max'} = '8'; + + if (defined($iThreadMax)) + { + $oParamHash{'global:backup'}{'thread-max'} = $iThreadMax; + } $oParamHash{'global:log'}{'level-file'} = 'trace'; - foreach my $strSection (keys $oParamHashRef) - { - foreach my $strKey (keys ${$oParamHashRef}{$strSection}) - { - $oParamHash{$strSection}{$strKey} = ${$oParamHashRef}{$strSection}{$strKey}; - } - } + # foreach my $strSection (keys $oParamHashRef) + # { + # foreach my $strKey (keys ${$oParamHashRef}{$strSection}) + # { + # $oParamHash{$strSection}{$strKey} = ${$oParamHashRef}{$strSection}{$strKey}; + # } + # } # Write out the configuration file my $strFile = BackRestTestCommon_TestPathGet() . '/pg_backrest.conf'; diff --git a/test/lib/BackRestTest/FileTest.pm b/test/lib/BackRestTest/FileTest.pm index 199a6e122..f303f993d 100755 --- a/test/lib/BackRestTest/FileTest.pm +++ b/test/lib/BackRestTest/FileTest.pm @@ -68,7 +68,6 @@ sub BackRestTestFile_Setup sub BackRestTestFile_Test { my $strTest = shift; - my $iTestRun = shift; # If no test was specified, then run them all if (!defined($strTest)) @@ -127,15 +126,9 @@ sub BackRestTestFile_Test { my $strPathType = PATH_BACKUP_CLUSTER; - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote ${bRemote}, error ${bError}, permission ${bPermission}"); + # Increment the run, log, and decide whether this unit test should be run + if (!BackRestTestCommon_Run(++$iRun, + "rmt ${bRemote}, err ${bError}, prm ${bPermission}")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -248,17 +241,11 @@ sub BackRestTestFile_Test # Loop through create for (my $bCreate = 0; $bCreate <= $bDestinationExists; $bCreate++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote" . - ", src_exists $bSourceExists, src_error $bSourceError" . - ", dst_exists $bDestinationExists, dst_error $bDestinationError, dst_create $bCreate"); + # Increment the run, log, and decide whether this unit test should be run + if (!BackRestTestCommon_Run(++$iRun, + "src_exists $bSourceExists, src_error $bSourceError, " . + ", dst_exists $bDestinationExists, dst_error $bDestinationError, " . + "dst_create $bCreate")) {next} # Setup test directory BackRestTestFile_Setup($bSourceError || $bDestinationError); @@ -343,15 +330,8 @@ sub BackRestTestFile_Test { for (my $bError = 0; $bError <= 1; $bError++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote, exists $bExists, error $bError"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt $bRemote, exists $bExists, err $bError")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -452,15 +432,8 @@ sub BackRestTestFile_Test { for (my $bExists = 0; $bExists <= 1; $bExists++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote, error $bError, exists $bExists"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt $bRemote, exists $bExists, err $bError")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -625,17 +598,10 @@ sub BackRestTestFile_Test # Loop through error for (my $bError = 0; $bError <= 1; $bError++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote, error $bError, exists $bExists, " . - "expression " . (defined($strExpression) ? $strExpression : "[undef]") . ", " . - "sort " . (defined($strSort) ? $strSort : "[undef]")); + if (!BackRestTestCommon_Run(++$iRun, + "rmt $bRemote, err $bError, exists $bExists, " . + "expression " . (defined($strExpression) ? $strExpression : "[undef]") . ", " . + "sort " . (defined($strSort) ? $strSort : "[undef]"))) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -740,16 +706,9 @@ sub BackRestTestFile_Test # Loop through ignore missing for (my $bIgnoreMissing = 0; $bIgnoreMissing <= 1; $bIgnoreMissing++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote ${bRemote}, error = $bError, exists ${bExists}, temp ${bTemp} " . - ", ignore missing ${bIgnoreMissing}"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt ${bRemote}, err = $bError, exists ${bExists}, tmp ${bTemp}, " . + "ignore missing ${bIgnoreMissing}")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -844,15 +803,8 @@ sub BackRestTestFile_Test # Loop through exists for (my $bExists = 0; $bExists <= 1; $bExists++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote, error $bError, exists $bExists"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt $bRemote, err $bError, exists $bExists")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -931,15 +883,8 @@ sub BackRestTestFile_Test # Loop through exists for (my $bError = 0; $bError <= $bExists; $bError++) { - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - " . - "remote $bRemote, exists $bExists, error ${bError}"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt $bRemote, err $bError, exists $bExists")) {next} # Setup test directory BackRestTestFile_Setup($bError); @@ -1057,21 +1002,17 @@ sub BackRestTestFile_Test my $strDestinationPathType = $bDestinationPathType ? PATH_DB_ABSOLUTE : PATH_BACKUP_ABSOLUTE; my $strDestinationPath = $bDestinationPathType ? "db" : "backup"; - $iRun++; - - if (defined($iTestRun) && $iTestRun != $iRun) - { - next; - } - - &log(INFO, "run ${iRun} - rmt " . - (defined($strRemote) && ($strRemote eq $strSourcePath || $strRemote eq $strDestinationPath) ? 1 : 0) . - ", lrg ${bLarge}, " . - "srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "remote" : "local") . - ":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " . - "srcignmiss ${bSourceIgnoreMissing}, " . - "dstpth " . (defined($strRemote) && $strRemote eq $strDestinationPath ? "remote" : "local") . - ":${strDestinationPath}, dstcmp $bDestinationCompress"); + if (!BackRestTestCommon_Run(++$iRun, + "rmt " . + (defined($strRemote) && ($strRemote eq $strSourcePath || + $strRemote eq $strDestinationPath) ? 1 : 0) . + ", lrg ${bLarge}, " . + "srcpth " . (defined($strRemote) && $strRemote eq $strSourcePath ? "rmt" : "lcl") . + ":${strSourcePath}, srccmp $bSourceCompressed, srcmiss ${bSourceMissing}, " . + "srcignmiss ${bSourceIgnoreMissing}, " . + "dstpth " . + (defined($strRemote) && $strRemote eq $strDestinationPath ? "rmt" : "lcl") . + ":${strDestinationPath}, dstcmp $bDestinationCompress")) {next} # Setup test directory BackRestTestFile_Setup(false); @@ -1198,6 +1139,11 @@ sub BackRestTestFile_Test } } } + + if (BackRestTestCommon_Cleanup()) + { + BackRestTestFile_Setup(undef, true); + } } 1; diff --git a/test/test.pl b/test/test.pl index 8f6b69b5c..33ffd8e6e 100755 --- a/test/test.pl +++ b/test/test.pl @@ -29,11 +29,15 @@ my $strLogLevel = 'off'; # Log level for tests my $strModule = 'all'; my $strModuleTest = 'all'; my $iModuleTestRun = undef; +my $bDryRun = false; +my $bNoCleanup = false; GetOptions ("log-level=s" => \$strLogLevel, "module=s" => \$strModule, "module-test=s" => \$strModuleTest, - "module-test-run=s" => \$iModuleTestRun) + "module-test-run=s" => \$iModuleTestRun, + "dry-run" => \$bDryRun, + "no-cleanup" => \$bNoCleanup) or die("Error in command line arguments\n"); #################################################################################################################################### @@ -55,9 +59,6 @@ if (defined($iModuleTestRun) && $strModuleTest eq 'all') confess "--module-test must be provided for run \"${iModuleTestRun}\""; } - -BackRestTestCommon_Setup(); - #################################################################################################################################### # Clean whitespace #################################################################################################################################### @@ -96,16 +97,22 @@ if (!$bMatch) #################################################################################################################################### # Runs tests #################################################################################################################################### -&log(INFO, "Testing with test_path = " . BackRestTestCommon_TestPathGet() . ", host = {strHost}, user = {strUser}, group = {strGroup}"); +BackRestTestCommon_Setup($iModuleTestRun, $bDryRun, $bNoCleanup); + +# &log(INFO, "Testing with test_path = " . BackRestTestCommon_TestPathGet() . ", host = {strHost}, user = {strUser}, " . +# "group = {strGroup}"); if ($strModule eq 'all' || $strModule eq "file") { - BackRestTestFile_Test($strModuleTest, $iModuleTestRun); + BackRestTestFile_Test($strModuleTest); } if ($strModule eq 'all' || $strModule eq "backup") { - BackRestTestBackup_Test($strModuleTest, $iModuleTestRun); + BackRestTestBackup_Test($strModuleTest); } -&log(ASSERT, "TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)"); +if (!$bDryRun) +{ + &log(ASSERT, "TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)"); +}