[PATCH] Make values() really sort as documented

Niko Tyni ntyni at debian.org
Mon Apr 18 18:06:04 UTC 2011


The values() method used to sort the returned list by the update time
(newest first), contrary to the documentation.

This was mostly missed by the test suite, except on rare occasions,
because the time stamps don't use sub-second precision. Only when the
threshold between full seconds happened in the middle of the data
insertion statements, the values() test in t/001Basic.t failed.

Fix the method, change the data insertion statement order, and add a
sleep statement in the middle to make sure the bug stays fixed.
---
 Historical.pm |    2 +-
 t/001Basic.t  |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Historical.pm b/Historical.pm
index e080642..b88b06a 100644
--- a/Historical.pm
+++ b/Historical.pm
@@ -178,7 +178,7 @@ sub values {
 
     my $values = Cache::Historical::Val::Manager->get_vals(
         query => [ @key ],
-        sort_by => ['upd_time DESC'],
+        sort_by => ['date'],
     );
 
     for(@$values) {
diff --git a/t/001Basic.t b/t/001Basic.t
index 67fac46..fee8145 100755
--- a/t/001Basic.t
+++ b/t/001Basic.t
@@ -17,8 +17,9 @@ my $c = Cache::Historical->new(
 my $fmt = DateTime::Format::Strptime->new(
               pattern => "%Y-%m-%d");
 
-$c->set( $fmt->parse_datetime("2008-01-02"), "msft", 35.22 );
 $c->set( $fmt->parse_datetime("2008-01-03"), "msft", 35.37 );
+$c->set( $fmt->parse_datetime("2008-01-02"), "msft", 35.22 );
+sleep 1; # so the update time is never the same for all the rows
 $c->set( $fmt->parse_datetime("2008-01-04"), "msft", 34.38 );
 $c->set( $fmt->parse_datetime("2008-01-07"), "msft", 34.61 );
 
-- 
1.7.4.1


--8t9RHnE3ZwKMSgU+--





More information about the pkg-perl-maintainers mailing list