From 060d5c095e650f35ea104fb4ae434ac598b81bca Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Tue, 19 Dec 2017 13:19:57 -0500 Subject: [PATCH] Bug 17770: Counter patch - sleep till past midnight. As per Jonathan's comment #14, added a wait_till_midnight function to t::lib::Dates. Running this test at 23:59 will trigger a sleep until after midnight accumulated in 60 second intervals. --- t/db_dependent/Sitemapper.t | 8 ++++---- t/lib/Dates.pm | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t index 4276470..379538d 100755 --- a/t/db_dependent/Sitemapper.t +++ b/t/db_dependent/Sitemapper.t @@ -24,12 +24,12 @@ use DateTime; use Test::MockModule; use Test::More tests => 16; use Koha::Schema; +use t::lib::Dates; -BEGIN { - use_ok('Koha::Sitemapper'); - use_ok('Koha::Sitemapper::Writer'); -} +t::lib::Dates::wait_till_midnight(1); +use_ok('Koha::Sitemapper'); +use_ok('Koha::Sitemapper::Writer'); sub slurp { my $file = shift; diff --git a/t/lib/Dates.pm b/t/lib/Dates.pm index 66299d9..6938a7d 100644 --- a/t/lib/Dates.pm +++ b/t/lib/Dates.pm @@ -28,4 +28,31 @@ sub compare { return $diff > 0 ? 1 : -1; } +=head2 wait_till_midnight + + $test_duration = 1; + t::lib::Dates::wait_till_midnight($test_duration); + +Some tests that cross midnight wrongly fail. This waits +until after midnight to ensure that the failure is not time related. + +I - The number of minutes the test takes to run + rounded up. Most run quickly, so a default + of 1 is sufficient when the parameter is + not passed. + +=cut + +sub wait_till_midnight { + my ($test_duration) = @_; + $test_duration = $test_duration // 1; + my $current_time = DateTime->now(); + if ($current_time->hour == 23 && $current_time->minute >= (60-$test_duration)) { + while ($current_time->hour == 23) { + sleep(60); + $current_time = DateTime->now(); + } + } +} + 1; -- 2.1.4