Bug 11470: fix occassional spurious test failure in Circulation_transfers.t
authorGalen Charlton <gmc@esilibrary.com>
Thu, 2 Jan 2014 18:02:17 +0000 (18:02 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 6 Jan 2014 05:31:21 +0000 (05:31 +0000)
This patch makes Circulation_transfers.t no longer be sensitive to
the exact time it runs, avoiding spurious test failures due
to datesent being a second off between the creation of the test
transfer and the comparison.

To test:

[1] To simulate the failure, add a "sleep(2);" after the
    "#Test GetTransfers" comment and run
    prove -v t/db_dependent/Circulation_transfers.t
[2] Remove the sleep and apply the patch.
[3] Verify that prove -v t/db_dependent/Circulation_transfers.t passes.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
t/db_dependent/Circulation_transfers.t

index 5328bde..25e720a 100644 (file)
@@ -10,6 +10,7 @@ use Koha::DateUtils;
 use DateTime::Duration;
 
 use Test::More tests => 19;
+use Test::Deep;
 
 BEGIN {
     use_ok('C4::Circulation');
@@ -140,13 +141,10 @@ is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef,
 #is(CreateBranchTransferLimit(-1,-1,'CODE'),0,"With wrong CreateBranchTransferLimit returns 0 - No transfertlimit added");
 
 #Test GetTransfers
-my $dt_today = dt_from_string( undef, 'sql', undef );
-my $today = $dt_today->strftime("%Y-%m-%d %H:%M:%S");
-
 my @transfers = GetTransfers($item_id1);
-is_deeply(
+cmp_deeply(
     \@transfers,
-    [ $today, $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ],
+    [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ],
     "Transfers of the item1"
 );    #NOTE: Only the first transfer is returned
 @transfers = GetTransfers;
@@ -159,17 +157,17 @@ is_deeply( \@transfers, [],
 #Test GetTransfersFromTo
 my @transferfrom1to2 = GetTransfersFromTo( $samplebranch1->{branchcode},
     $samplebranch2->{branchcode} );
-is_deeply(
+cmp_deeply(
     \@transferfrom1to2,
     [
         {
             itemnumber => $item_id1,
-            datesent   => $today,
+            datesent   => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'),
             frombranch => $samplebranch1->{branchcode}
         },
         {
             itemnumber => $item_id2,
-            datesent   => $today,
+            datesent   => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'),
             frombranch => $samplebranch1->{branchcode}
         }
     ],