Skip to content

Instantly share code, notes, and snippets.

@Oscil8
Created April 2, 2011 05:00
Show Gist options
  • Save Oscil8/604a6fd34580e472e129 to your computer and use it in GitHub Desktop.
Save Oscil8/604a6fd34580e472e129 to your computer and use it in GitHub Desktop.
Redistat tests for boundary conditions
diff --git a/spec/finder_spec.rb b/spec/finder_spec.rb
index 0af91a6..3414389 100644
--- a/spec/finder_spec.rb
+++ b/spec/finder_spec.rb
@@ -71,6 +71,34 @@ describe Redistat::Finder do
stats.first.should == stats.total
end
+ it "should fetch stats properly near day boundary" do
+ first_stat, last_stat = create_day_boundary_stats
+
+ stats = Redistat::Finder.find({:from => first_stat, :till => last_stat, :scope => @scope, :labe
+ stats.from.should == first_stat
+ stats.till.should == last_stat
+ stats.depth.should == :hour
+
+ stats.total.should == @stats
+ stats.total.from.should == first_stat
+ stats.total.till.should == last_stat
+ stats.first.should == stats.total
+ end
+
+ it "should fetch stats properly near month boundary" do
+ first_stat, last_stat = create_month_boundary_stats
+
+ stats = Redistat::Finder.find({:from => first_stat, :till => last_stat, :scope => @scope, :labe
+ stats.from.should == first_stat
+ stats.till.should == last_stat
+ stats.depth.should == :day
+
+ stats.total.should == @stats
+ stats.total.from.should == first_stat
+ stats.total.till.should == last_stat
+ stats.first.should == stats.total
+ end
+
it "should fetch data per unit when interval option is specified" do
first_stat, last_stat = create_example_stats
@@ -204,4 +232,20 @@ describe Redistat::Finder do
[first - 1.hour, last + 1.hour]
end
+ def create_day_boundary_stats
+ key = Redistat::Key.new(@scope, @label, (first = Time.parse("2011-02-22 23:55:00")))
+ Redistat::Summary.update(key, @stats, :hour)
+ key = Redistat::Key.new(@scope, @label, (after = Time.parse("2011-02-23 00:05:00")))
+ Redistat::Summary.update(key, @stats, :hour)
+ [first.beginning_of_hour, after.beginning_of_hour]
+ end
+
+ def create_month_boundary_stats
+ key = Redistat::Key.new(@scope, @label, (first = Time.parse("2011-02-28 12:22")))
+ Redistat::Summary.update(key, @stats, :day)
+ key = Redistat::Key.new(@scope, @label, (after = Time.parse("2011-03-01 08:08")))
+ Redistat::Summary.update(key, @stats, :day)
+ [first.beginning_of_day, after.beginning_of_day]
+ end
+
end
Failures:
1) Redistat::Finder should fetch stats properly near day boundary
Failure/Error: stats.total.should == @stats
expected: {"visitors"=>2, "views"=>3}
got: {"views"=>6, "visitors"=>4} (using ==)
Diff:
@@ -1,2 +1,2 @@
-{"visitors"=>2, "views"=>3}
+{"views"=>6, "visitors"=>4}
2) Redistat::Finder should fetch stats properly near month boundary
Failure/Error: stats.total.should == @stats
expected: {"visitors"=>2, "views"=>3}
got: {"views"=>6, "visitors"=>4} (using ==)
Diff:
@@ -1,2 +1,2 @@
-{"visitors"=>2, "views"=>3}
+{"views"=>6, "visitors"=>4}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment