From bd7451dc3bc0c059ca39a978a828d13193aa7570 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Fri, 21 Aug 2015 15:43:42 +0300 Subject: [PATCH] Add failing spec simulating race condition. --- spec/redis/connection/celluloid_spec.rb | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/redis/connection/celluloid_spec.rb b/spec/redis/connection/celluloid_spec.rb index 7aa3ada..bf9237b 100644 --- a/spec/redis/connection/celluloid_spec.rb +++ b/spec/redis/connection/celluloid_spec.rb @@ -21,4 +21,40 @@ expect { redis.shutdown }.not_to raise_error end end + + describe "using inside Celluloid::IO" do + before do + class Incrementor + include Celluloid::IO + + def initialize + @redis = Redis.new(:driver => :celluloid) + end + + def increment! + sleep(rand / 10) + @redis.incr 'rabbits' + rescue + STDERR.puts "I cannot increment rabbits because of #{$!.inspect}!" + raise RuntimeError + end + end + end + + let(:actor) { + Incrementor.new + } + let(:count) { 1000 } + + it "just survives" do + redis = Redis.new + redis.set 'rabbits', 0 + + count.times do + actor.async.increment! rescue nil + end + sleep 10 + expect(redis.get 'rabbits').to eq(count.to_s) + end + end end