You've already forked pgbackrest
							
							
				mirror of
				https://github.com/pgbackrest/pgbackrest.git
				synced 2025-10-30 23:37:45 +02:00 
			
		
		
		
	Unit tests will now work across all installed versions of Postgres.
Created a function to list all supported versions. Now used for all version checking.
This commit is contained in:
		| @@ -118,6 +118,7 @@ sub walFileName | ||||
|  | ||||
|     # Record the start time | ||||
|     my $lTime = time(); | ||||
|     my $fSleep = .1; | ||||
|  | ||||
|     # Determine the path where the requested WAL segment is located | ||||
|     my $strArchivePath = dirname($oFile->path_get(PATH_BACKUP_ARCHIVE, $strWalSegment)); | ||||
| @@ -143,15 +144,16 @@ sub walFileName | ||||
|         # If waiting then sleep before trying again | ||||
|         if (defined($iWaitSeconds)) | ||||
|         { | ||||
|             hsleep(.5); | ||||
|             hsleep($fSleep); | ||||
|             $fSleep = $fSleep * 2 < $iWaitSeconds - (time() - $lTime) ? $fSleep * 2 : ($iWaitSeconds - (time() - $lTime)) + .1; | ||||
|         } | ||||
|     } | ||||
|     while (defined($iWaitSeconds) && $lTime > time() - $iWaitSeconds); | ||||
|     while (defined($iWaitSeconds) && (time() - $lTime) < $iWaitSeconds); | ||||
|  | ||||
|     # If waiting and no WAL segment was found then throw an error | ||||
|     if (defined($iWaitSeconds)) | ||||
|     { | ||||
|         confess &log(ERROR, "could not find WAL segment ${strWalSegment} after ${iWaitSeconds} second(s)"); | ||||
|         confess &log(ERROR, "could not find WAL segment ${strWalSegment} after " . (time() - $lTime)  . ' second(s)'); | ||||
|     } | ||||
|  | ||||
|     return undef; | ||||
| @@ -235,7 +237,7 @@ sub walInfo | ||||
|     # } | ||||
|     else | ||||
|     { | ||||
|         confess &log(ERROR, "unexpected xlog magic 0x" . sprintf("%X", $iMagic) . ' (unsupported PostgreSQL version)', | ||||
|         confess &log(ERROR, "unexpected xlog magic 0x" . sprintf("%X", $iMagic) . ' (unsupported PostgreSQL version?)', | ||||
|                      ERROR_VERSION_NOT_SUPPORTED); | ||||
|     } | ||||
|  | ||||
| @@ -595,7 +597,8 @@ sub xfer | ||||
|  | ||||
|     foreach my $strFile (sort(keys $oManifestHash{name})) | ||||
|     { | ||||
|         if ($strFile =~ /^[0-F]{24}.*/ || $strFile =~ /^[0-F]{8}\.history$/) | ||||
|         if ($strFile =~ "^[0-F]{24}(-[0-f]{40})(\\.$oFile->{strCompressExtension}){0,1}\$" || | ||||
|             $strFile =~ /^[0-F]{8}\.history$/ || $strFile =~ /^[0-F]{24}\.[0-F]{8}\.backup$/) | ||||
|         { | ||||
|             CORE::push(@stryFile, $strFile); | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ use IPC::System::Simple qw(capture); | ||||
| use Exporter qw(import); | ||||
|  | ||||
| use lib dirname($0); | ||||
| use BackRest::Exception; | ||||
| use BackRest::Utility; | ||||
|  | ||||
| #################################################################################################################################### | ||||
| @@ -71,6 +72,20 @@ sub is_remote | ||||
|     return defined($self->{oDbSSH}) ? true : false; | ||||
| } | ||||
|  | ||||
| #################################################################################################################################### | ||||
| # versionSupport | ||||
| # | ||||
| # Returns an array of the supported Postgres versions. | ||||
| #################################################################################################################################### | ||||
| sub versionSupport | ||||
| { | ||||
|     my @strySupportVersion = ('8.3', '8.4', '9.0', '9.1', '9.2', '9.3', '9.4'); | ||||
|  | ||||
|     return \@strySupportVersion; | ||||
| } | ||||
|  | ||||
| push @EXPORT, qw(versionSupport); | ||||
|  | ||||
| #################################################################################################################################### | ||||
| # PSQL_EXECUTE | ||||
| #################################################################################################################################### | ||||
| @@ -132,6 +147,13 @@ sub db_version_get | ||||
|  | ||||
|     &log(DEBUG, "database version is $self->{fVersion}"); | ||||
|  | ||||
|     my $strVersionSupport = versionSupport(); | ||||
|  | ||||
|     if ($self->{fVersion} < ${$strVersionSupport}[0]) | ||||
|     { | ||||
|         confess &log(ERROR, "unsupported Postgres version ${$strVersionSupport}[0]", ERROR_VERSION_NOT_SUPPORTED); | ||||
|     } | ||||
|  | ||||
|     return $self->{fVersion}; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -321,7 +321,7 @@ sub path_get | ||||
|                 confess &log(ASSERT, 'archive temp must have strFile defined'); | ||||
|             } | ||||
|  | ||||
|             return "${strArchivePath}.tmp"; | ||||
|             $strArchivePath = "${strArchivePath}.tmp"; | ||||
|         } | ||||
|  | ||||
|         return $strArchivePath; | ||||
|   | ||||
| @@ -25,6 +25,7 @@ use BackRest::Config; | ||||
| use BackRest::Remote; | ||||
| use BackRest::File; | ||||
| use BackRest::Manifest; | ||||
| use BackRest::Db; | ||||
|  | ||||
| use Exporter qw(import); | ||||
| our @EXPORT = qw(BackRestTestCommon_Create BackRestTestCommon_Drop BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin | ||||
| @@ -477,10 +478,12 @@ sub BackRestTestCommon_Setup | ||||
|     @stryVersionToken = split(/\./, $stryVersionToken[2]); | ||||
|     $strCommonDbVersion = $stryVersionToken[0] . '.' . $stryVersionToken[1]; | ||||
|  | ||||
|     # Don't run unit tests for versions below 8.3 | ||||
|     if ($strCommonDbVersion < 8.3) | ||||
|     # Don't run unit tests for unsupported versions | ||||
|     my $strVersionSupport = versionSupport(); | ||||
|  | ||||
|     if ($strCommonDbVersion < ${$strVersionSupport}[0]) | ||||
|     { | ||||
|         confess "currently only version 8.3 and up are supported"; | ||||
|         confess "currently only version ${$strVersionSupport}[0] and up are supported"; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										63
									
								
								test/test.pl
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								test/test.pl
									
									
									
									
									
								
							| @@ -17,6 +17,7 @@ use Pod::Usage; | ||||
| #use Test::More; | ||||
|  | ||||
| use lib dirname($0) . '/../lib'; | ||||
| use BackRest::Db; | ||||
| use BackRest::Utility; | ||||
|  | ||||
| use lib dirname($0) . '/lib'; | ||||
| @@ -46,6 +47,7 @@ test.pl [options] | ||||
|    --dry-run            show only the tests that would be executed but don't execute them | ||||
|    --no-cleanup         don't cleaup after the last test is complete - useful for debugging | ||||
|    --infinite           repeat selected tests forever | ||||
|    --db-version         version of postgres to test (or all) | ||||
|  | ||||
|  Configuration Options: | ||||
|    --psql-bin           path to the psql executables (e.g. /usr/lib/postgresql/9.3/bin/) | ||||
| @@ -61,7 +63,7 @@ test.pl [options] | ||||
| #################################################################################################################################### | ||||
| # Command line parameters | ||||
| #################################################################################################################################### | ||||
| my $strLogLevel = 'info';   # Log level for tests | ||||
| my $strLogLevel = 'info'; | ||||
| my $strModule = 'all'; | ||||
| my $strModuleTest = 'all'; | ||||
| my $iModuleTestRun = undef; | ||||
| @@ -74,6 +76,7 @@ my $bVersion = false; | ||||
| my $bHelp = false; | ||||
| my $bQuiet = false; | ||||
| my $bInfinite = false; | ||||
| my $strDbVersion = 'max'; | ||||
|  | ||||
| GetOptions ('q|quiet' => \$bQuiet, | ||||
|             'version' => \$bVersion, | ||||
| @@ -87,7 +90,8 @@ GetOptions ('q|quiet' => \$bQuiet, | ||||
|             'thread-max=s' => \$iThreadMax, | ||||
|             'dry-run' => \$bDryRun, | ||||
|             'no-cleanup' => \$bNoCleanup, | ||||
|             'infinite' => \$bInfinite) | ||||
|             'infinite' => \$bInfinite, | ||||
|             'db-version=s' => \$strDbVersion) | ||||
|     or pod2usage(2); | ||||
|  | ||||
| # Display version and exit if requested | ||||
| @@ -104,7 +108,11 @@ if ($bVersion || $bHelp) | ||||
|     exit 0; | ||||
| } | ||||
|  | ||||
| # Test::More->builder->output('/dev/null'); | ||||
| if (@ARGV > 0) | ||||
| { | ||||
|     print "invalid parameter\n\n"; | ||||
|     pod2usage(); | ||||
| } | ||||
|  | ||||
| #################################################################################################################################### | ||||
| # Setup | ||||
| @@ -131,30 +139,39 @@ if (defined($iModuleTestRun) && $strModuleTest eq 'all') | ||||
| } | ||||
|  | ||||
| # Search for psql bin | ||||
| my @stryTestVersion; | ||||
| my $strVersionSupport = versionSupport(); | ||||
|  | ||||
| if (!defined($strPgSqlBin)) | ||||
| { | ||||
|     my @strySearchPath = ('/usr/lib/postgresql/VERSION/bin', '/Library/PostgreSQL/VERSION/bin'); | ||||
|  | ||||
|     foreach my $strSearchPath (@strySearchPath) | ||||
|     { | ||||
|         for (my $fVersion = 9; $fVersion >= 0; $fVersion -= 1) | ||||
|         for (my $iVersionIdx = @{$strVersionSupport} - 1; $iVersionIdx >= 0; $iVersionIdx--) | ||||
|         { | ||||
|             my $strVersionPath = $strSearchPath; | ||||
|             $strVersionPath =~ s/VERSION/9\.$fVersion/g; | ||||
|  | ||||
|             if (-e "${strVersionPath}/initdb") | ||||
|             if ($strDbVersion eq 'all' || $strDbVersion eq 'max' && @stryTestVersion == 0 || | ||||
|                 $strDbVersion eq ${$strVersionSupport}[$iVersionIdx]) | ||||
|             { | ||||
|                 &log(INFO, "found pgsql-bin at ${strVersionPath}\n"); | ||||
|                 $strPgSqlBin = ${strVersionPath}; | ||||
|                 last; | ||||
|                 my $strVersionPath = $strSearchPath; | ||||
|                 $strVersionPath =~ s/VERSION/${$strVersionSupport}[$iVersionIdx]/g; | ||||
|  | ||||
|                 if (-e "${strVersionPath}/initdb") | ||||
|                 { | ||||
|                     &log(INFO, "FOUND pgsql-bin at ${strVersionPath}"); | ||||
|                     push @stryTestVersion, $strVersionPath; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (!defined($strPgSqlBin)) | ||||
|     { | ||||
|         confess 'pgsql-bin was not defined and could not be located'; | ||||
|     } | ||||
|     # Make sure at least one version of postgres was found | ||||
|     @{$strVersionSupport} > 0 | ||||
|         or confess 'pgsql-bin was not defined and postgres could not be located automatically'; | ||||
| } | ||||
| else | ||||
| { | ||||
|     push @stryTestVersion, $strPgSqlBin; | ||||
| } | ||||
|  | ||||
| # Check thread total | ||||
| @@ -214,8 +231,6 @@ if (-e './test.pl' && -e '../bin/pg_backrest.pl' && open($hVersion, '<', '../VER | ||||
| #################################################################################################################################### | ||||
| # Runs tests | ||||
| #################################################################################################################################### | ||||
| BackRestTestCommon_Setup($strTestPath, $strPgSqlBin, $iModuleTestRun, $bDryRun, $bNoCleanup); | ||||
|  | ||||
| # &log(INFO, "Testing with test_path = " . BackRestTestCommon_TestPathGet() . ", host = {strHost}, user = {strUser}, " . | ||||
| #            "group = {strGroup}"); | ||||
|  | ||||
| @@ -223,6 +238,10 @@ my $iRun = 0; | ||||
|  | ||||
| do | ||||
| { | ||||
|     BackRestTestCommon_Setup($strTestPath, $stryTestVersion[0], $iModuleTestRun, $bDryRun, $bNoCleanup); | ||||
|  | ||||
|     &log(INFO, "TESTING psql-bin = $stryTestVersion[0]\n"); | ||||
|  | ||||
|     if ($bInfinite) | ||||
|     { | ||||
|         $iRun++; | ||||
| @@ -247,6 +266,16 @@ do | ||||
|     if ($strModule eq 'all' || $strModule eq 'backup') | ||||
|     { | ||||
|         BackRestTestBackup_Test($strModuleTest, $iThreadMax); | ||||
|  | ||||
|         if (@stryTestVersion > 1 && ($strModuleTest eq 'all' || $strModuleTest eq 'full')) | ||||
|         { | ||||
|             for (my $iVersionIdx = 1; $iVersionIdx < @stryTestVersion; $iVersionIdx++) | ||||
|             { | ||||
|                 BackRestTestCommon_Setup($strTestPath, $stryTestVersion[$iVersionIdx], $iModuleTestRun, $bDryRun, $bNoCleanup); | ||||
|                 &log(INFO, "TESTING psql-bin = $stryTestVersion[$iVersionIdx] for backup/full\n"); | ||||
|                 BackRestTestBackup_Test('full', $iThreadMax); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| while ($bInfinite); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user