From 09e2351ae8b17a8eaccba81337e16fc4d7aeb7a4 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 9 Aug 2014 18:35:55 -0400 Subject: [PATCH] Test log mode is working. --- bin/pg_backrest.pl | 2 +- lib/BackRest/Backup.pm | 4 +--- lib/BackRest/Db.pm | 2 +- lib/BackRest/Utility.pm | 28 ++++++++++++++++------------ test/lib/BackRestTest/BackupTest.pm | 3 ++- test/lib/BackRestTest/CommonTest.pm | 2 +- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/bin/pg_backrest.pl b/bin/pg_backrest.pl index 278c1b5e2..588a467d0 100755 --- a/bin/pg_backrest.pl +++ b/bin/pg_backrest.pl @@ -75,7 +75,7 @@ my $strType; # Type of backup: full, differential (diff), incremental # Test parameters - not for general use my $bNoFork = false; # Prevents the archive process from forking when local archiving is enabled my $bTest = false; # Enters test mode - not harmful in anyway, but adds special logging and pauses for unit testing -my $iTestDelay = 2; # Amount of time to delay after hitting a test point (the default would not be enough for manual tests) +my $iTestDelay = 5; # Amount of time to delay after hitting a test point (the default would not be enough for manual tests) GetOptions ("config=s" => \$strConfigFile, "stanza=s" => \$strStanza, diff --git a/lib/BackRest/Backup.pm b/lib/BackRest/Backup.pm index f701abe7a..7c43de18b 100644 --- a/lib/BackRest/Backup.pm +++ b/lib/BackRest/Backup.pm @@ -1286,8 +1286,6 @@ sub backup &log(DEBUG, "cluster path is $strDbClusterPath"); # Create the cluster backup path - # $oFile->path_create(PATH_BACKUP, "backup", undef, true); - # $oFile->path_create(PATH_BACKUP, "temp", undef, true); $oFile->path_create(PATH_BACKUP_CLUSTER, undef, undef, true); # Find the previous backup based on the type @@ -1394,7 +1392,7 @@ sub backup # After the backup has been stopped, need to make a copy of the archive logs need to make the db consistent &log(DEBUG, "retrieving archive logs ${strArchiveStart}:${strArchiveStop}"); - my @stryArchive = archive_list_get($strArchiveStart, $strArchiveStop, $oDb->version_get() < 9.3); + my @stryArchive = archive_list_get($strArchiveStart, $strArchiveStop, $oDb->db_version_get() < 9.3); foreach my $strArchive (@stryArchive) { diff --git a/lib/BackRest/Db.pm b/lib/BackRest/Db.pm index 18c7a156a..317629fce 100644 --- a/lib/BackRest/Db.pm +++ b/lib/BackRest/Db.pm @@ -104,7 +104,7 @@ sub tablespace_map_get } #################################################################################################################################### -# VERSION_GET +# DB_VERSION_GET #################################################################################################################################### sub db_version_get { diff --git a/lib/BackRest/Utility.pm b/lib/BackRest/Utility.pm index 0d179c092..1353dad57 100644 --- a/lib/BackRest/Utility.pm +++ b/lib/BackRest/Utility.pm @@ -72,7 +72,7 @@ use constant # Test global variables my $bTest = false; -my $iTestDelay = 2; +my $iTestDelay; #################################################################################################################################### # VERSION_GET @@ -399,29 +399,31 @@ sub log my $iCode = shift; my $strMessageFormat = $strMessage; + my $iLogLevelRank = $oLogLevelRank{"${strLevel}"}{rank}; - if ($bTest && $strLevel eq TEST) + if ($strLevel eq TEST) { + $iLogLevelRank = $oLogLevelRank{TRACE}{rank} + 1; $strMessageFormat = TEST_ENCLOSE . '-' . $strMessageFormat . '-' . TEST_ENCLOSE; } - elsif (!defined($oLogLevelRank{"${strLevel}"}{rank})) + elsif (!defined($iLogLevelRank)) { confess &log(ASSERT, "log level ${strLevel} does not exist"); } - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); if (!defined($strMessageFormat)) { $strMessageFormat = "(undefined)"; } - if ($strLevel eq "TRACE") + if ($strLevel eq TRACE || $strLevel eq TEST) { $strMessageFormat =~ s/\n/\n /g; $strMessageFormat = " " . $strMessageFormat; } - elsif ($strLevel eq "DEBUG") + elsif ($strLevel eq DEBUG) { $strMessageFormat =~ s/\n/\n /g; $strMessageFormat = " " . $strMessageFormat; @@ -436,13 +438,19 @@ sub log (" " x (7 - length($strLevel))) . "${strLevel}: ${strMessageFormat}" . (defined($iCode) ? " (code ${iCode})" : "") . "\n"; - if ($oLogLevelRank{"${strLevel}"}{rank} <= $oLogLevelRank{"${strLogLevelConsole}"}{rank} || + # if ($strLevel eq TEST) + # { + # confess "log level rank $iLogLevelRank"; + # } + + if ($iLogLevelRank <= $oLogLevelRank{"${strLogLevelConsole}"}{rank} || $bTest && $strLevel eq TEST) { print $strMessageFormat; } - if ($oLogLevelRank{"${strLevel}"}{rank} <= $oLogLevelRank{"${strLogLevelFile}"}{rank}) + if ($iLogLevelRank <= $oLogLevelRank{"${strLogLevelFile}"}{rank} || + $bTest && $strLevel eq TEST) { if (defined($hLogFile)) { @@ -481,7 +489,6 @@ sub config_load while (my $strLine = readline($hFile)) { $strLine = trim($strLine); -# print "line:${strLine}\n"; if ($strLine ne '') { @@ -489,7 +496,6 @@ sub config_load if (index($strLine, '[') == 0) { $strSection = substr($strLine, 1, length($strLine) - 2); -# print "found section ${strSection}\n"; } else { @@ -504,8 +510,6 @@ sub config_load my $strKey = substr($strLine, 0, $iIndex); my $strValue = substr($strLine, $iIndex + 1); -# print "found key ${strKey}:${strValue}\n"; - # Try to store value as JSON eval { diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index d919878ae..a34913d0c 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -69,8 +69,9 @@ sub BackRestTestBackup_ClusterCreate " --config=" . BackRestTestCommon_DbPathGet() . "/pg_backrest.conf archive-push %p"; BackRestTestCommon_Execute("initdb -D $strPath -A trust"); - BackRestTestCommon_Execute("/Library/PostgreSQL/9.3/bin/pg_ctl start -o \"-c port=$iPort -c checkpoint_segments=1 " . + BackRestTestCommon_Execute("pg_ctl start -o \"-c port=$iPort -c checkpoint_segments=1 " . "-c wal_level=archive -c archive_mode=on -c archive_command='$strArchive'\" " . +# "-c unix_socket_directories='" . BackRestTestCommon_DbCommonPathGet() . "'\" " . "-D $strPath -l $strPath/postgresql.log -w -s"); } diff --git a/test/lib/BackRestTest/CommonTest.pm b/test/lib/BackRestTest/CommonTest.pm index 68491839b..f1ca2b773 100755 --- a/test/lib/BackRestTest/CommonTest.pm +++ b/test/lib/BackRestTest/CommonTest.pm @@ -142,7 +142,7 @@ sub BackRestTestCommon_Execute if ($iExitStatus != 0 && !$bSuppressError) { - confess &log(ERROR, "command '${strCommand}' returned " . $iExitStatus . + confess &log(ERROR, "command '${strCommand}' returned " . $iExitStatus . "\n" . ($strOutLog ne '' ? "STDOUT:\n${strOutLog}" : '') . ($strErrorLog ne '' ? "STDERR:\n${strErrorLog}" : '')); }