Skip to content

Commit

Permalink
Fix test failure such as TravisCI build 314 due to timing issues
Browse files Browse the repository at this point in the history
In TravisCI build 314, time wrapped to the next minute between writing
data to the various tables and the test verification (which generated
its own(!) time values).

This commit uses the same time value for both the output in the tables
as for test verification, preventing unnecessary failures.
  • Loading branch information
ehuelsmann committed Apr 24, 2021
1 parent d35c782 commit cadd26f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ SPOPS = 0
[Prereqs / TestRequires]
DBD::Mock = 0.10
List::MoreUtils = 0
Mock::MonkeyPatch = 0
Test::Exception = 0
Test::More = 0.88
Test::Kwalitee = 1.21 ; from Dist::Zilla
Expand Down
15 changes: 13 additions & 2 deletions t/persister_dbi.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

use strict;
use lib qw(../lib lib ../t t);

use Mock::MonkeyPatch;
use TestUtil;
use constant NUM_TESTS => 50;

use Test::More;
use Test::Exception;

Expand Down Expand Up @@ -93,6 +96,14 @@ my ( $wf );
}

{
my $now = DateTime->now();
my $nowstr = $now->strftime( $DATE_FORMAT );
# Prevent test failure due to minute-wrapping between
# preparing the query and verifying the result
my $mock = Mock::MonkeyPatch->patch(
'DateTime::now' => sub { $now->clone }
);

TestUtil->set_new_ticket_context( $wf );
my $old_state = $wf->state();
$wf->execute_action( 'TIX_NEW' );
Expand All @@ -117,7 +128,7 @@ my ( $wf );
'due date', 'last update' ],
[ $ticket_id, $ticket_info{type}, $ticket_info{subject},
$ticket_info{description}, $ticket_info{creator}, $old_state,
$ticket_info{due_date}->strftime( '%Y-%m-%d' ), DateTime->now->strftime( $DATE_FORMAT ) ]
$ticket_info{due_date}->strftime( '%Y-%m-%d' ), $nowstr ]
);

my $link_create = $history->[1];
Expand All @@ -128,7 +139,7 @@ my ( $wf );
TestUtil->check_workflow_history(
$hst_update,
[ $wf_id, 'Create ticket', $history_desc,
'TIX_CREATED', $ticket_info{creator}, DateTime->now->strftime( $DATE_FORMAT ),
'TIX_CREATED', $ticket_info{creator}, $nowstr,
sub { my ( $val ) = @_; return ( length( $val ), 8 ) } ]
);

Expand Down

0 comments on commit cadd26f

Please sign in to comment.