pgbackrest.git / summary / log / commit / refs
commit b031dbbcf8fa83ef60cfabc20fbf16046904f9aa
Author: David Steele <david@pgmasters.net>
Date: Thu Dec 12 03:11:04 2019 +0000
Allow timezones to be explicitly set for testing.
The TZ environment variable was not reliably pushed down to the test processes.
Instead pass TZ via a command line parameter and set explicitly in the test process.
.travis.yml | 3 +--
test/lib/pgBackRestTest/Common/JobTest.pm | 13 +++++++++++++
test/src/test.c | 3 +++
test/test.pl | 12 +++++++++++-
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 65b7f6f37..f1749c8e7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,8 +21,7 @@ matrix:
- env: PGB_CI="test --vm=co7 --param=module=mock --param=module=real"
- dist: bionic
env:
- - PGB_CI="test --vm=none"
- - TZ="America/New_York"
+ - PGB_CI="test --vm=none --param=tz=America/New_York"
services:
- env: PGB_CI=" doc --vm=co6"
- env: PGB_CI=" doc --vm=co7"
diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm
index a6b3e1dc9..e8140ecea 100644
--- a/test/lib/pgBackRestTest/Common/JobTest.pm
+++ b/test/lib/pgBackRestTest/Common/JobTest.pm
@@ -76,6 +76,7 @@ sub new
$self->{bBackTrace},
$self->{bProfile},
$self->{iScale},
+ $self->{strTimeZone},
$self->{bDebug},
$self->{bDebugTestTrace},
$self->{iBuildMax},
@@ -107,6 +108,7 @@ sub new
{name => 'bBackTrace'},
{name => 'bProfile'},
{name => 'iScale'},
+ {name => 'strTimeZone', required => false},
{name => 'bDebug'},
{name => 'bDebugTestTrace'},
{name => 'iBuildMax'},
@@ -278,6 +280,7 @@ sub run
(defined($self->{oTest}->{&TEST_DB}) ? ' --pg-version=' . $self->{oTest}->{&TEST_DB} : '') .
($self->{strLogLevel} ne lc(INFO) ? " --log-level=$self->{strLogLevel}" : '') .
' --pgsql-bin=' . $self->{oTest}->{&TEST_PGSQL_BIN} .
+ ($self->{strTimeZone} ? " --tz='$self->{strTimeZone}'" : '') .
($self->{bLogForce} ? ' --log-force' : '') .
($self->{bDryRun} ? ' --dry-run' : '') .
($self->{bDryRun} ? ' --vm-out' : '') .
@@ -394,6 +397,16 @@ sub run
$strTestC =~ s/\{\[C\_TEST\_REPO_PATH\]\}/$self->{strBackRestBase}/g;
$strTestC =~ s/\{\[C\_TEST\_SCALE\]\}/$self->{iScale}/g;
+ # Set timezone
+ if (defined($self->{strTimeZone}))
+ {
+ $strTestC =~ s/\{\[C\_TEST\_TZ\]\}/setenv\("TZ", "$self->{strTimeZone}", true\);/g;
+ }
+ else
+ {
+ $strTestC =~ s/\{\[C\_TEST\_TZ\]\}/\/\/ No timezone specified/g;
+ }
+
# Set default log level
my $strLogLevelTestC = "logLevel" . ucfirst($self->{strLogLevelTest});
$strTestC =~ s/\{\[C\_LOG\_LEVEL\_TEST\]\}/$strLogLevelTestC/g;
diff --git a/test/src/test.c b/test/src/test.c
index 86bc5aec3..7ecb367ad 100644
--- a/test/src/test.c
+++ b/test/src/test.c
@@ -73,6 +73,9 @@ main(int argListSize, const char *argList[])
// Set neutral umask for testing
umask(0000);
+ // Set timezone if specified
+ {[C_TEST_TZ]}
+
// Ignore SIGPIPE and check for EPIPE errors on write() instead
signal(SIGPIPE, SIG_IGN);
diff --git a/test/test.pl b/test/test.pl
index f5d46ac18..65bc99bbb 100755
--- a/test/test.pl
+++ b/test/test.pl
@@ -97,6 +97,7 @@ test.pl [options]
--profile generate profile info
--no-debug don't generate a debug build
--scale scale performance tests
+ --tz test with the specified timezone
--debug-test-trace test stack trace for low-level functions (slow, esp w/valgrind, may cause timeouts)
Report Options:
@@ -169,6 +170,7 @@ my $bNoDebug = false;
my $iScale = 1;
my $bDebugTestTrace = false;
my $iRetry = 0;
+my $strTimeZone = undef;
my @cmdOptions = @ARGV;
@@ -215,6 +217,7 @@ GetOptions ('q|quiet' => \$bQuiet,
'no-optimize' => \$bNoOptimize,
'no-debug', => \$bNoDebug,
'scale=s' => \$iScale,
+ 'tz=s', => \$strTimeZone,
'debug-test-trace', => \$bDebugTestTrace,
'retry=s' => \$iRetry)
or pod2usage(2);
@@ -1322,7 +1325,8 @@ eval
$oStorageTest, $strBackRestBase, $strTestPath, $$oyTestRun[$iTestIdx], $bDryRun, $strVmHost, $bVmOut,
$iVmIdx, $iVmMax, $iTestIdx, $iTestMax, $strLogLevel, $strLogLevelTest, $bLogForce, $bShowOutputAsync,
$bNoCleanup, $iRetry, !$bNoValgrind, !$bNoCoverage, $bCoverageSummary, !$bNoOptimize, $bBackTrace,
- $bProfile, $iScale, !$bNoDebug, $bDebugTestTrace, $iBuildMax / $iVmMax < 1 ? 1 : int($iBuildMax / $iVmMax));
+ $bProfile, $iScale, $strTimeZone, !$bNoDebug, $bDebugTestTrace,
+ $iBuildMax / $iVmMax < 1 ? 1 : int($iBuildMax / $iVmMax));
$iTestIdx++;
if ($oJob->run())
@@ -1514,6 +1518,12 @@ eval
# Create host group for containers
my $oHostGroup = hostGroupGet();
+ # Set timezone
+ if (defined($strTimeZone))
+ {
+ $ENV{TZ} = $strTimeZone;
+ }
+
# Run the test
testRun($stryModule[0], $stryModuleTest[0])->process(
$strVm, $iVmId, # Vm info
[parent: db5175915a0d]