Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit 0320953

Browse files
committed
Add failing spec simulating race condition.
1 parent bf8790b commit 0320953

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spec/redis/connection/celluloid_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,40 @@
2121
expect { redis.shutdown }.not_to raise_error
2222
end
2323
end
24+
25+
describe "using inside Celluloid::IO" do
26+
before do
27+
class Incrementor
28+
include Celluloid::IO
29+
30+
def initialize
31+
@redis = Redis.new(:driver => :celluloid)
32+
end
33+
34+
def increment!
35+
sleep(rand / 10)
36+
@redis.incr 'rabbits'
37+
rescue
38+
STDERR.puts "I cannot increment rabbits because of #{$!.inspect}!"
39+
raise RuntimeError
40+
end
41+
end
42+
end
43+
44+
let(:actor) {
45+
Incrementor.new
46+
}
47+
let(:count) { 1000 }
48+
49+
it "just survives" do
50+
redis = Redis.new
51+
redis.set 'rabbits', 0
52+
53+
count.times do
54+
actor.async.increment! rescue nil
55+
end
56+
sleep 2
57+
expect(redis.get 'rabbits').to eq(count.to_s)
58+
end
59+
end
2460
end

0 commit comments

Comments
 (0)