Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

redis race condition fixed. specs broken. commit to branch until buil…

…d is green
  • Loading branch information...
commit e56a8748d90e47357f6ed6a3ce72d3b1dfec9132 1 parent 7206ca2
@stevegraham authored
View
14 Gemfile.lock
@@ -5,8 +5,9 @@ PATH
activesupport (~> 3.1)
em-hiredis (~> 0.1.0)
em-http-request (~> 0.3.0)
+ em-synchrony (~> 1.0.3)
em-websocket (~> 0.3.5)
- eventmachine (~> 0.12.10)
+ eventmachine (~> 1.0.0.beta.1)
glamazon (~> 0.3.1)
rack (~> 1.5)
rack-fiber_pool (~> 0.9.2)
@@ -20,7 +21,7 @@ GEM
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
- addressable (2.3.2)
+ addressable (2.3.3)
crack (0.3.2)
daemons (1.1.9)
diff-lcs (1.1.3)
@@ -30,24 +31,24 @@ GEM
addressable (>= 2.0.0)
escape_utils
eventmachine (>= 0.12.9)
+ em-synchrony (1.0.3)
+ eventmachine (>= 1.0.0.beta.1)
em-websocket (0.3.8)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
escape_utils (0.2.4)
- eventmachine (0.12.10)
- eventmachine (0.12.10-java)
+ eventmachine (1.0.0)
glamazon (0.3.1)
activesupport (>= 3.1.0)
i18n (~> 0.6.0)
yajl-ruby (>= 0.7.7)
haml (3.1.8)
hiredis (0.4.5)
- hiredis (0.4.5-java)
i18n (0.6.1)
metaclass (0.0.1)
mocha (0.13.2)
metaclass (~> 0.0.1)
- multi_json (1.6.0)
+ multi_json (1.6.1)
pusher (0.11.3)
multi_json (~> 1.0)
signature (~> 0.1.6)
@@ -78,7 +79,6 @@ GEM
yajl-ruby (1.1.0)
PLATFORMS
- java
ruby
DEPENDENCIES
View
3  bin/slanger
@@ -3,6 +3,7 @@
require 'optparse'
require 'bundler/setup'
require 'eventmachine'
+require 'em-synchrony'
options = {
api_host: '0.0.0.0', api_port: '4567', websocket_host: '0.0.0.0',
@@ -83,7 +84,7 @@ end
EM.epoll
EM.kqueue
-EM.run do
+EM.synchrony do
File.tap { |f| require f.expand_path(f.join(f.dirname(__FILE__),'..', 'slanger.rb')) }
Slanger::Config.load options
Slanger::Service.run
View
2  lib/slanger/presence_channel.rb
@@ -44,7 +44,7 @@ def subscribe(msg, callback, &blk)
# fuuuuuuuuuccccccck!
publisher.callback do
- EM.next_tick do
+ EM::Synchrony.next_tick do
# The Subscription event has been sent to Redis successfully.
# Call the provided callback.
callback.call
View
21 lib/slanger/redis.rb
@@ -2,6 +2,17 @@
# Interface with Redis.
require 'forwardable'
+require 'em-synchrony'
+
+# Make EM::Hiredis.connect work with EM::Synchrony.sync
+EM::Hiredis::Client.class_eval do
+ alias _succeed succeed
+
+ def succeed *args
+ _succeed self
+ super
+ end
+end
module Slanger
module Redis
@@ -24,15 +35,17 @@ def publisher
def subscriber
@subscriber ||= new_connection.tap do |c|
c.on(:message) do |channel, message|
- message = JSON.parse message
- c = Channel.from message['channel']
- c.dispatch message, channel
+ EM.synchrony do
+ message = JSON.parse message
+ c = Channel.from message['channel']
+ c.dispatch message, channel
+ end
end
end
end
def new_connection
- EM::Hiredis.connect Slanger::Config.redis_address
+ EM::Synchrony.sync(EM::Hiredis.connect Slanger::Config.redis_address)
end
extend self
View
17 lib/slanger/web_socket_server.rb
@@ -1,4 +1,5 @@
require 'eventmachine'
+require 'em-synchrony'
require 'em-websocket'
module Slanger
@@ -7,7 +8,7 @@ def run
EM.epoll
EM.kqueue
- EM.run do
+ EM.synchrony do
options = {
host: Slanger::Config[:websocket_host],
port: Slanger::Config[:websocket_port],
@@ -24,9 +25,17 @@ def run
# Keep track of handler instance in instance of EM::Connection to ensure a unique handler instance is used per connection.
ws.class_eval { attr_accessor :connection_handler }
# Delegate connection management to handler instance.
- ws.onopen { ws.connection_handler = Slanger::Config.socket_handler.new ws }
- ws.onmessage { |msg| ws.connection_handler.onmessage msg }
- ws.onclose { ws.connection_handler.onclose }
+ ws.onopen do
+ ws.connection_handler = Slanger::Config.socket_handler.new ws
+ end
+
+ ws.onmessage do |msg|
+ EM.synchrony { ws.connection_handler.onmessage msg }
+ end
+
+ ws.onclose do
+ ws.connection_handler.onclose
+ end
end
end
end
View
3  slanger.gemspec
@@ -13,7 +13,8 @@ Gem::Specification.new do |s|
s.email = 'sjtgraham@mac.com'
s.homepage = 'http://github.com/stevegraham/slanger'
- s.add_dependency 'eventmachine', '~> 0.12.10'
+ s.add_dependency 'eventmachine', '~> 1.0.0.beta.1'
+ s.add_dependency 'em-synchrony', '~> 1.0.3'
s.add_dependency 'em-hiredis', '~> 0.1.0'
s.add_dependency 'em-websocket', '~> 0.3.5'
s.add_dependency 'rack', '~> 1.5'
View
4 spec/integration/integration_spec.rb
@@ -25,7 +25,9 @@
end
end
- EM.run { new_websocket.tap { |u| u.stream { EM.next_tick { EM.stop } } }}
+ EM.synchrony do
+ new_websocket.tap { |u| u.stream { EM.next_tick { EM.stop } } }
+ end
end
end
end
View
2  spec/slanger_helper_methods.rb
@@ -59,7 +59,7 @@ def em_stream opts = {}
def em_thread
Thread.new do
- EM.run do
+ EM.synchrony do
yield
end
end.join
View
4 spec/spec_helper.rb
@@ -3,6 +3,7 @@
require 'active_support/json'
require 'active_support/core_ext/hash'
require 'eventmachine'
+require 'em-synchrony'
require 'em-http-request'
require 'pusher'
require 'thin'
@@ -39,4 +40,7 @@ def errback
p.key = '765ec374ae0a69f4ce44'
end
end
+ config.around(:each) do |example|
+ Fiber.new { example.run }.resume
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.