Bug 21238: Prevent TemplateToolkit.t to fail on slow servers
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 16 Aug 2018 15:29:43 +0000 (12:29 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 21 Sep 2018 13:13:05 +0000 (15:13 +0200)
It failed 3x in the last 6 runs (on node 1), we should mock
DateTime->now to prevent it to fail again.

The error is:
koha_1       |         #   Failed test at
t/db_dependent/Letters/TemplateToolkit.t line 724.

When comparing <<today>> replacement:
koha_1       |         # 08/16/2018 14:25<br />
[...]
koha_1       |         # 08/16/2018 14:24<br />

Let's mock DateTime->now to prevent it to fail again.

Test plan:
0. Do not apply this patch
1. Add "sleep(60);" at line ~715, before "# Add a second checkout"
2. Run the tests
=> Fail!
3. Apply this patch
4. Run the tests again
=> Pass!

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit d24d77d495a56e76046907ab19e9474cab28169c)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit fba97f0772ad6fd40b359e626ce9fb82f3d92182)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

t/db_dependent/Letters/TemplateToolkit.t

index 3509201..22d8aa4 100644 (file)
@@ -20,6 +20,7 @@
 
 use Modern::Perl;
 use Test::More tests => 18;
+use Test::MockModule;
 use Test::Warn;
 
 use MARC::Record;
@@ -56,7 +57,9 @@ $dbh->{RaiseError} = 1;
 
 $dbh->do(q|DELETE FROM letter|);
 
-my $date = dt_from_string;
+my $now_value       = DateTime->now();
+my $mocked_datetime = Test::MockModule->new('DateTime');
+$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
 
 my $library = $builder->build( { source => 'Branch' } );
 my $patron  = $builder->build( { source => 'Borrower' } );