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

Unit tests now working on Ubuntu 12.04

This commit is contained in:
David Steele
2014-08-10 21:22:17 -04:00
parent 0298e8dd16
commit 6b4a8fbc21
8 changed files with 98 additions and 39 deletions

View File

@@ -4,3 +4,32 @@
## configuration
## sample ubuntu 12.04 install
apt-get update
apt-get upgrade (reboot if required)
apt-get install ssh
apt-get install cpanminus
apt-get install postgresql-9.3
apt-get install postgresql-server-dev-9.3
cpanm JSON
cpanm Moose
cpanm Net::OpenSSH
cpanm DBI
cpanm DBD::Pg
cpanm IPC::System::Simple
Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository
deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
For unit tests:
create backrest user
setup trusted ssh between test user account and backrest
backrest user and test user must be in the same group

View File

@@ -8,7 +8,6 @@
####################################################################################################################################
use strict;
use warnings;
use english;
use File::Basename;
use Getopt::Long;

View File

@@ -97,8 +97,6 @@ sub BUILD
($self->{hIn}, $self->{hOut}, $self->{hErr}, $self->{pId}) = $self->{oSSH}->open3($self->{strCommand});
$self->greeting_read();
# print "BUILT THREAD " . (defined($self->{iThreadIdx}) ? $self->{iThreadIdx} : 'undef') . "\n";
}
$self->{oThreadQueue} = Thread::Queue->new();
@@ -115,11 +113,6 @@ sub thread_kill
if (defined($self->{oThread}))
{
# if (defined($self->{strHost}))
# {
# print "DEM THREAD " . (defined($self->{iThreadIdx}) ? $self->{iThreadIdx} : 'undef') . "\n";
# }
$self->{oThreadQueue}->enqueue(undef);
$self->{oThread}->join();
$self->{oThread} = undef;

View File

@@ -9,7 +9,6 @@ package BackRestTest::BackupTest;
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;
@@ -93,7 +92,7 @@ sub BackRestTestBackup_ClusterStop
# If postmaster process is running them stop the cluster
if (-e $strPath . "/postmaster.pid")
{
BackRestTestCommon_Execute("pg_ctl stop -D $strPath -w -s -m fast");
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl stop -D $strPath -w -s -m fast");
}
}
@@ -110,7 +109,7 @@ sub BackRestTestBackup_ClusterRestart
# If postmaster process is running them stop the cluster
if (-e $strPath . "/postmaster.pid")
{
BackRestTestCommon_Execute("pg_ctl restart -D $strPath -w -s");
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/pg_ctl restart -D $strPath -w -s");
}
# Connect user session
@@ -128,9 +127,9 @@ sub BackRestTestBackup_ClusterCreate
my $strArchive = BackRestTestCommon_CommandMainGet() . " --stanza=" . BackRestTestCommon_StanzaGet() .
" --config=" . BackRestTestCommon_DbPathGet() . "/pg_backrest.conf archive-push %p";
BackRestTestCommon_Execute("initdb -D $strPath -A trust");
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' " .
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/initdb -D ${strPath} -A trust");
BackRestTestCommon_Execute(BackRestTestCommon_PgSqlBinPathGet() . "/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_DbPathGet() . "'\" " .
"-D $strPath -l $strPath/postgresql.log -w -s");
@@ -234,7 +233,7 @@ sub BackRestTestBackup_Test
my $iArchiveMax = 3;
my $strXlogPath = BackRestTestCommon_DbCommonPathGet() . '/pg_xlog';
my $strArchiveTestFile = BackRestTestCommon_DataPathGet() . '/test.archive.bin';
my $iThreadMax = 8;
my $iThreadMax = 4; #8;
# Print test banner
&log(INFO, "BACKUP MODULE ******************************************************************");
@@ -571,7 +570,8 @@ sub BackRestTestBackup_Test
for (my $iIncr = 0; $iIncr <= 1; $iIncr++)
{
&log(INFO, " " . ($iIncr == 0 ? "full " : " incr ") . sprintf("%02d", $iFull));
&log(INFO, " " . ($iIncr == 0 ? ("full " . sprintf("%02d", $iFull)) :
(" incr " . sprintf("%02d", $iIncr))));
BackRestTestBackup_PgExecute('create table test (id int)');
@@ -589,7 +589,7 @@ sub BackRestTestBackup_Test
}
BackRestTestCommon_Execute($strCommand, $bRemote);
# BackRestTestCommon_Execute($strCommand, $bRemote);
}
}
}

View File

@@ -9,7 +9,6 @@ package BackRestTest::CommonTest;
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;
@@ -26,12 +25,13 @@ use Exporter qw(import);
our @EXPORT = qw(BackRestTestCommon_Setup BackRestTestCommon_ExecuteBegin BackRestTestCommon_ExecuteEnd
BackRestTestCommon_Execute BackRestTestCommon_ExecuteBackRest
BackRestTestCommon_ConfigCreate BackRestTestCommon_Run BackRestTestCommon_Cleanup
BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet BackRestTestCommon_CommandRemoteGet
BackRestTestCommon_HostGet BackRestTestCommon_UserGet BackRestTestCommon_GroupGet
BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet BackRestTestCommon_DataPathGet
BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet BackRestTestCommon_DbPathGet
BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbPortGet);
BackRestTestCommon_PgSqlBinPathGet BackRestTestCommon_StanzaGet BackRestTestCommon_CommandMainGet
BackRestTestCommon_CommandRemoteGet BackRestTestCommon_HostGet BackRestTestCommon_UserGet
BackRestTestCommon_GroupGet BackRestTestCommon_UserBackRestGet BackRestTestCommon_TestPathGet
BackRestTestCommon_DataPathGet BackRestTestCommon_BackupPathGet BackRestTestCommon_ArchivePathGet
BackRestTestCommon_DbPathGet BackRestTestCommon_DbCommonPathGet BackRestTestCommon_DbPortGet);
my $strPgSqlBin;
my $strCommonStanza;
my $strCommonCommandMain;
my $strCommonCommandRemote;
@@ -198,19 +198,31 @@ sub BackRestTestCommon_Execute
####################################################################################################################################
sub BackRestTestCommon_Setup
{
my $strTestPathParam = shift;
my $strPgSqlBinParam = shift;
my $iModuleTestRunParam = shift;
my $bDryRunParam = shift;
my $bNoCleanupParam = shift;
my $strBasePath = dirname(dirname(abs_path($0)));
$strPgSqlBin = $strPgSqlBinParam;
$strCommonStanza = "db";
$strCommonHost = '127.0.0.1';
$strCommonUser = getpwuid($<);
$strCommonGroup = getgrgid($();
$strCommonUserBackRest = 'backrest';
if (defined($strTestPathParam))
{
$strCommonTestPath = $strTestPathParam;
}
else
{
$strCommonTestPath = "${strBasePath}/test/test";
}
$strCommonDataPath = "${strBasePath}/test/data";
$strCommonBackupPath = "${strCommonTestPath}/backrest";
$strCommonArchivePath = "${strCommonTestPath}/archive";
@@ -219,8 +231,7 @@ sub BackRestTestCommon_Setup
$strCommonCommandMain = "${strBasePath}/bin/pg_backrest.pl";
$strCommonCommandRemote = "${strBasePath}/bin/pg_backrest_remote.pl";
$strCommonCommandPsql = "/Library/PostgreSQL/9.3/bin/psql -X %option% -h ${strCommonDbPath}";
# $strCommonCommandPsql = 'psql -X %option%';
$strCommonCommandPsql = "${strPgSqlBin}/psql -X %option% -h ${strCommonDbPath}";
$iCommonDbPort = 6543;
$iModuleTestRun = $iModuleTestRunParam;
@@ -341,6 +352,11 @@ sub BackRestTestCommon_ConfigCreate
####################################################################################################################################
# Get Methods
####################################################################################################################################
sub BackRestTestCommon_PgSqlBinPathGet
{
return $strPgSqlBin;
}
sub BackRestTestCommon_StanzaGet
{
return $strCommonStanza;

View File

@@ -9,7 +9,6 @@ package BackRestTest::FileTest;
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;

View File

@@ -9,7 +9,6 @@ package BackRestTest::UtilityTest;
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;

View File

@@ -8,11 +8,12 @@
####################################################################################################################################
use strict;
use warnings;
use english;
use Carp;
use File::Basename;
use Getopt::Long;
use Carp;
use Cwd 'abs_path';
use Cwd;
use lib dirname($0) . "/../lib";
use BackRest::Utility;
@@ -32,8 +33,12 @@ my $strModuleTest = 'all';
my $iModuleTestRun = undef;
my $bDryRun = false;
my $bNoCleanup = false;
my $strPgSqlBin;
my $strTestPath;
GetOptions ("log-level=s" => \$strLogLevel,
GetOptions ("pgsql-bin=s" => \$strPgSqlBin,
"test-path=s" => \$strTestPath,
"log-level=s" => \$strLogLevel,
"module=s" => \$strModule,
"module-test=s" => \$strModuleTest,
"module-test-run=s" => \$iModuleTestRun,
@@ -60,13 +65,11 @@ if (defined($iModuleTestRun) && $strModuleTest eq 'all')
confess "--module-test must be provided for run \"${iModuleTestRun}\"";
}
####################################################################################################################################
# Clean whitespace
####################################################################################################################################
BackRestTestCommon_Execute("find .. -type f -not -path \"../.git/*\" -not -path \"*.DS_Store\" -not -path \"../test/test/*\" " .
"-not -path \"../test/data/*\" " .
"-exec sh -c 'for i;do echo \"\$i\" && sed 's/[[:space:]]*\$//' \"\$i\">/tmp/.\$\$ && cat /tmp/.\$\$ " .
"> \"\$i\";done' arg0 {} + > /dev/null", false, true);
# Make sure PG bin has been defined
if (!defined($strPgSqlBin))
{
confess "pgsql-bin was not defined";
}
####################################################################################################################################
# Make sure version number matches in README.md and VERSION
@@ -95,10 +98,31 @@ if (!$bMatch)
confess "unable to find version ${strVersion} as last revision in README.md";
}
####################################################################################################################################
# Clean whitespace only if test.pl is being run from the test directory in the backrest repo
####################################################################################################################################
my $hVersion;
if (-e "./test.pl" && -e "../bin/pg_backrest.pl" && open($hVersion, "<", "../VERSION"))
{
my $strTestVersion = readline($hVersion);
if (defined($strTestVersion) && $strVersion eq trim($strTestVersion))
{
BackRestTestCommon_Execute(
"find .. -type f -not -path \"../.git/*\" -not -path \"*.DS_Store\" -not -path \"../test/test/*\" " .
"-not -path \"../test/data/*\" " .
"-exec sh -c 'for i;do echo \"\$i\" && sed 's/[[:space:]]*\$//' \"\$i\">/tmp/.\$\$ && cat /tmp/.\$\$ " .
"> \"\$i\";done' arg0 {} + > /dev/null", false, true);
}
close($hVersion);
}
####################################################################################################################################
# Runs tests
####################################################################################################################################
BackRestTestCommon_Setup($iModuleTestRun, $bDryRun, $bNoCleanup);
BackRestTestCommon_Setup($strTestPath, $strPgSqlBin, $iModuleTestRun, $bDryRun, $bNoCleanup);
# &log(INFO, "Testing with test_path = " . BackRestTestCommon_TestPathGet() . ", host = {strHost}, user = {strUser}, " .
# "group = {strGroup}");