Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Clear redis before every test #15

Merged
merged 4 commits into from

2 participants

@billywatson

Ran into some errors when trying to create new redis tests, a lot of inconsistent results. I believe the majority of it was due to not clearing redis before every test.

Sorry about not submitting separate pull requests. I can if you wish, but I also fixed a few other tiny errors. Thanks!

spec/native_spec.rb
@@ -21,9 +21,20 @@
bf1.include?("test").should be_true
bf2.include?("test").should be_true
end
+
+ it "should store data in filter up to 10% of filter size" do
@igrigorik Owner

Why 10%, this seems like an arbitrary limit? You can push as much data as you want, you'll simply tradeoff against collisions.

Theoretically, you should have 0 collisions at this point.

And really, if this isn't a good test, that's fine. I was also trying to test the clearing of redis did something. If you ramp this up from 10%, then more than this test would fail if you didn't clear redis. So whatever you think is best.

@igrigorik Owner

There is no guarantee that there will be 0 collisions. Bloomfilters are probabilistic data structures.. It is highly unlikely that you will get a collision with your configuration, but it is possible -- which makes for some great heisen failures in your test suite. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@billywatson

Okay got rid of those tests :)

@igrigorik igrigorik merged commit 846a687 into igrigorik:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2012
  1. correct a spelling error

    William Watson authored
  2. add .rvmrc and .ds_store files to .gitignore

    William Watson authored
  3. flush the entire redis database before each example

    William Watson authored
Commits on Apr 29, 2012
  1. fix assertions and comments for change to BloomFilter::ConfigurationM…

    William Watson authored
    …ismatch
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -1,6 +1,8 @@
*.o
*.bundle
*.swp
+.rvmrc
+.DS_Store
ext/Makefile
lib/cbloomfilter.so
tmp
View
4 lib/bloomfilter/native.rb
@@ -45,7 +45,7 @@ def set_bits
# Computes the intersection of two Bloom filters.
# It assumes that both filters have the same size -
- # if this is not true +ArgumentError+ is raised.
+ # if this is not true +BloomFilter::ConfigurationMismatch+ is raised.
def &(o)
raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
@@ -55,7 +55,7 @@ def &(o)
# Computes the union of two Bloom filters.
# It assumes that both filters have the same size -
- # if this is not true +ArgumentError+ is raised.
+ # if this is not true +BloomFilter::ConfigurationMismatch+ is raised.
def |(o)
raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
View
65 spec/counting_redis_spec.rb
@@ -5,21 +5,43 @@
describe CountingRedis do
context "use Redis for storage" do
- it "should store data in Redis" do
- bf = CountingRedis.new
-
- bf.insert(:abcd)
- bf.insert('test')
- bf.include?('test').should be_true
- bf.key?('test').should be_true
-
- bf.include?('test', 'test2').should be_false
- bf.include?('test', 'abcd').should be_true
+ context "a default CountingRedis instance" do
+ let(:bf) { CountingRedis.new }
+
+ before do
+ # clear all redis databases
+ bf.instance_variable_get(:@db).flushall
+ end
+
+ it "should store data in Redis" do
+ bf.insert(:abcd)
+ bf.insert('test')
+ bf.include?('test').should be_true
+ bf.key?('test').should be_true
+
+ bf.include?('test', 'test2').should be_false
+ bf.include?('test', 'abcd').should be_true
+ end
+
+ it "should delete keys from Redis" do
+ bf.insert('test')
+ bf.include?('test').should be_true
+
+ bf.delete('test')
+ bf.include?('test').should be_false
+ end
+
+ it "should output current stats" do
+ bf.insert('test')
+ bf.size.should == 4
+ lambda { bf.stats }.should_not raise_error
+ end
end
-
+
it "should accept a TTL value for a key" do
bf = CountingRedis.new(:ttl => 1)
-
+ bf.instance_variable_get(:@db).flushall
+
bf.insert('test')
bf.include?('test').should be_true
@@ -27,25 +49,6 @@
bf.include?('test').should be_false
end
- it "should delete keys from Redis" do
- bf = CountingRedis.new
-
- bf.insert('test')
- bf.include?('test').should be_true
-
- bf.delete('test')
- bf.include?('test').should be_false
- end
-
- it "should output current stats" do
- bf = CountingRedis.new
- bf.clear
-
- bf.insert('test')
- bf.size.should == 4
- lambda { bf.stats }.should_not raise_error
- end
-
it "should connect to remote redis server" do
lambda { CountingRedis.new }.should_not raise_error
end
View
4 spec/native_spec.rb
@@ -23,7 +23,7 @@
end
context "behave like a bloomfilter" do
- it "should test set memerbship" do
+ it "should test set membership" do
bf = Native.new(:size => 100, :hashes => 2, :seed => 1, :bucket => 3, :raise => false)
bf.insert("test")
bf.insert("test1")
@@ -103,7 +103,7 @@
bf2 = Native.new(:size => 20)
bf2.insert("test")
- proc {bf1 | bf2}.should raise_error(ArgumentError)
+ proc {bf1 | bf2}.should raise_error(BloomFilter::ConfigurationMismatch)
end
end
View
5 spec/redis_spec.rb
@@ -5,6 +5,11 @@
context "use Redis bitstring for storage" do
let(:bf) { BloomFilter::Redis.new }
+ before do
+ # clear all redis databases
+ bf.instance_variable_get(:@db).flushall
+ end
+
it "should store data in Redis" do
bf.insert(:abcd)
bf.insert('test')
Something went wrong with that request. Please try again.