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

Detected race condition. #19

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--color
--format documentation
--backtrace
--default_path spec
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sudo: false

rvm:
- 1.9.3
- 2.0.0
Expand All @@ -15,3 +17,6 @@ matrix:

notifications:
irc: "irc.freenode.org#celluloid"

services:
- redis-server
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ source 'https://rubygems.org'
gemspec

gem 'coveralls', require: false
gem 'celluloid', github: 'celluloid/celluloid'
gem 'celluloid-io', github: 'celluloid/celluloid-io'
gem 'celluloid', github: 'celluloid/celluloid', submodules: true
gem 'celluloid-io', github: 'celluloid/celluloid-io', submodules: true
2 changes: 1 addition & 1 deletion celluloid-redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'celluloid/redis/version'

Gem::Specification.new do |spec|
spec.name = "celluloid-redis"
spec.version = Celluloid::Redis::VERSION
spec.version = CelluloidRedis::VERSION
spec.authors = ["Tony Arcieri"]
spec.email = ["[email protected]"]
spec.description = "Celluloid::IO support for the redis-rb library"
Expand Down
23 changes: 22 additions & 1 deletion lib/celluloid/redis.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
require "redis"

require "celluloid/redis/version"
require "celluloid/redis/redis_ext"
require "celluloid/io"

module Celluloid
class Redis < ::Redis
VERSION = CelluloidRedis::VERSION

def initialize(*args)
super
if @options[:driver] == :celluloid
@latch = Celluloid::IO::Stream::Latch.new
end
end

def synchronize
if @latch
@latch.synchronize { yield @client }
else
super(&proc)
end
end
end
end
28 changes: 0 additions & 28 deletions lib/celluloid/redis/redis_ext.rb

This file was deleted.

6 changes: 2 additions & 4 deletions lib/celluloid/redis/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module Celluloid
module Redis
VERSION = "0.0.2"
end
module CelluloidRedis
VERSION = "0.0.2"
end
36 changes: 36 additions & 0 deletions spec/redis/connection/celluloid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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