diff --git a/.env-ci b/.env-ci new file mode 100644 index 0000000..04573e7 --- /dev/null +++ b/.env-ci @@ -0,0 +1,4 @@ +CELLULOID_SPECS_LOG_STRATEGY=stderr +CELLULOID_SPECS_LOG_LEVEL=3 +CELLULOID_SPECS_LOG_FILE=log/ci.log +CELLULOID_SPECS_LOG_SYNC=false diff --git a/.env-dev b/.env-dev new file mode 100644 index 0000000..91e6111 --- /dev/null +++ b/.env-dev @@ -0,0 +1,4 @@ +CELLULOID_SPECS_LOG_STRATEGY=single +CELLULOID_SPECS_LOG_FILE=log/test.log +CELLULOID_SPECS_LOG_LEVEL=0 +CELLULOID_SPECS_LOG_SYNC=true diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7f72185 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "culture"] + path = culture + url = http://github.com/celluloid/culture.git diff --git a/.travis.yml b/.travis.yml index f068588..1e9abd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ rvm: matrix: fast_finish: true allow_failures: - - rvm: jruby - - rvm: rbx-2 - rvm: ruby-head - rvm: jruby-head diff --git a/CHANGES.md b/CHANGES.md index cd9a0ec..28be134 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,37 +1,43 @@ +0.70.0 +----- +* Adapted to be compliant with version 0.17.0 of Celluloid. +* Added `write_to` for use with `Router` sockets. +* Added more direct set/get of socket identity. + 0.16.1 (2015-04-26) -------------------- +----- * Support for XPUB sockets * Support for reading multipart messages * Spec cleanup 0.16.0 (2014-09-04) -------------------- +----- * Support for setting socket options * More specs 0.15.0 (2013-09-04) -------------------- +----- * Tracking release for Celluloid 0.15 0.14.0 (2013-05-07) -------------------- +----- * Add pubsub example * Add identity support to Sockets * Depend on EventedMailbox from core instead of celluloid-io * Remove overhead for IO waiting by calling directly to the reactor 0.13.0 ------- +----- * Feature: Support for DealerSocket and RouterSocket * Support for the #more_parts? method on sockets * Celluloid 0.13 compatibility fixes 0.12.0 ------- +----- * Tracking release for Celluloid 0.12.0 0.10.0 ------- +----- * Factor celluloid-zmq into its own gem * #linger= support diff --git a/Gemfile b/Gemfile index 1e283b8..2e4054c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,2 @@ -source 'http://rubygems.org' - -gem 'coveralls', require: false -gem 'celluloid', github: 'celluloid/celluloid', branch: 'master' -gem 'transpec', github: 'yujinakayama/transpec', tag: 'v3.1.0' - -# Specify your gem's dependencies in celluloid-zmq.gemspec -gemspec +require File.expand_path("../culture/sync", __FILE__) +Celluloid::Sync::Gemfile[self] diff --git a/celluloid-zmq.gemspec b/celluloid-zmq.gemspec index 536da28..7230968 100644 --- a/celluloid-zmq.gemspec +++ b/celluloid-zmq.gemspec @@ -1,5 +1,5 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/celluloid/zmq/version', __FILE__) +require File.expand_path("../culture/sync", __FILE__) Gem::Specification.new do |gem| gem.authors = ["Tony Arcieri"] @@ -12,13 +12,10 @@ Gem::Specification.new do |gem| gem.name = "celluloid-zmq" gem.version = Celluloid::ZMQ::VERSION - gem.add_dependency "celluloid", "~> 0.16" + Celluloid::Sync::Gemspec[gem] gem.add_dependency "ffi" gem.add_dependency "ffi-rzmq" - gem.add_development_dependency "rake" - gem.add_development_dependency "rspec", "~> 3.0" - # Files ignores = File.read(".gitignore").split(/\r?\n/).reject{ |f| f =~ /^(#.+|\s*)$/ }.map {|f| Dir[f] }.flatten gem.files = (Dir['**/*','.gitignore'] - ignores).reject {|f| !File.file?(f) } diff --git a/culture b/culture new file mode 160000 index 0000000..5f92523 --- /dev/null +++ b/culture @@ -0,0 +1 @@ +Subproject commit 5f925237663e18fd6931444dc6f8378264a238d6 diff --git a/examples/publish_subscribe.rb b/examples/publish_subscribe.rb index e91aa37..024871d 100644 --- a/examples/publish_subscribe.rb +++ b/examples/publish_subscribe.rb @@ -1,4 +1,6 @@ -require 'celluloid/zmq' +require 'celluloid/zmq/current' + +Celluloid::ZMQ.init class PublishSubscribe include Celluloid::ZMQ @@ -6,11 +8,11 @@ class PublishSubscribe def run link = "tcp://127.0.0.1:5555" - s1 = PubSocket.new - s2 = SubSocket.new - s3 = SubSocket.new - s4 = SubSocket.new - s5 = SubSocket.new + s1 = Socket::Pub.new + s2 = Socket::Sub.new + s3 = Socket::Sub.new + s4 = Socket::Sub.new + s5 = Socket::Sub.new s1.linger = 100 s2.subscribe('') # receive all diff --git a/lib/celluloid/zmq.rb b/lib/celluloid/zmq.rb index 5b49dfb..2dceb2d 100644 --- a/lib/celluloid/zmq.rb +++ b/lib/celluloid/zmq.rb @@ -1,16 +1,23 @@ require 'ffi-rzmq' -require 'celluloid' +$CELLULOID_ZMQ_BACKPORTED = (ENV["CELLULOID_ZMQ_BACKPORTED"] != "false") unless defined?($CELLULOID_ZMQ_BACKPORTED) + +require ($CELLULOID_ZMQ_BACKPORTED) ? 'celluloid' : 'celluloid/current' + require 'celluloid/zmq/mailbox' require 'celluloid/zmq/reactor' -require 'celluloid/zmq/sockets' +require 'celluloid/zmq/socket' require 'celluloid/zmq/version' require 'celluloid/zmq/waker' +require 'celluloid/zmq/socket/readable' +require 'celluloid/zmq/socket/writable' +require 'celluloid/zmq/socket/types' + module Celluloid # Actors which run alongside 0MQ sockets module ZMQ - UninitializedError = Class.new StandardError + class UninitializedError < Celluloid::Error; end class << self attr_writer :context @@ -65,5 +72,12 @@ def wait_writable(socket) end module_function :wait_writable + def result_ok?(result) + ::ZMQ::Util.resultcode_ok?(result) + end + module_function :result_ok? + end end + +require 'celluloid/zmq/deprecate' unless $CELLULOID_BACKPORTED == false || $CELLULOID_ZMQ_BACKPORTED == false diff --git a/lib/celluloid/zmq/current.rb b/lib/celluloid/zmq/current.rb new file mode 100644 index 0000000..0e0dd15 --- /dev/null +++ b/lib/celluloid/zmq/current.rb @@ -0,0 +1,2 @@ +$CELLULOID_ZMQ_BACKPORTED = false +require "celluloid/zmq" diff --git a/lib/celluloid/zmq/deprecate.rb b/lib/celluloid/zmq/deprecate.rb new file mode 100644 index 0000000..807d94b --- /dev/null +++ b/lib/celluloid/zmq/deprecate.rb @@ -0,0 +1,15 @@ +module Celluloid + module ZMQ + ReadableSocket = Socket::Readable + WritableSocket = Socket::Writable + RepSocket = Socket::Rep + ReqSocket = Socket::Req + DealerSocket = Socket::Dealer + RouterSocket = Socket::Router + PushSocket = Socket::Push + PullSocket = Socket::Pull + PubSocket = Socket::Pub + XPubSocket = Socket::XPub + SubSocket = Socket::Sub + end +end diff --git a/lib/celluloid/zmq/mailbox.rb b/lib/celluloid/zmq/mailbox.rb index fdccf45..6f75566 100644 --- a/lib/celluloid/zmq/mailbox.rb +++ b/lib/celluloid/zmq/mailbox.rb @@ -1,7 +1,7 @@ module Celluloid module ZMQ # Replacement mailbox for Celluloid::ZMQ actors - class Mailbox < Celluloid::EventedMailbox + class Mailbox < Celluloid::Mailbox::Evented def initialize super(Reactor) end diff --git a/lib/celluloid/zmq/reactor.rb b/lib/celluloid/zmq/reactor.rb index 132bfa4..8f5b6b3 100644 --- a/lib/celluloid/zmq/reactor.rb +++ b/lib/celluloid/zmq/reactor.rb @@ -3,10 +3,11 @@ module ZMQ # React to incoming 0MQ and Celluloid events. This is kinda sorta supposed # to resemble the Reactor design pattern. class Reactor - extend Forwardable + extend Forwardable def_delegator :@waker, :signal, :wakeup def_delegator :@waker, :cleanup, :shutdown + def_delegator ZMQ, :result_ok? def initialize @waker = Waker.new @@ -15,7 +16,7 @@ def initialize @writers = {} rc = @poller.register @waker.socket, ::ZMQ::POLLIN - unless ::ZMQ::Util.resultcode_ok? rc + unless result_ok? rc raise "0MQ poll error: #{::ZMQ::Util.error_string}" end end @@ -55,7 +56,7 @@ def run_once(timeout = nil) rc = @poller.poll(timeout) - unless ::ZMQ::Util.resultcode_ok? rc + unless result_ok? rc raise IOError, "0MQ poll error: #{::ZMQ::Util.error_string}" end diff --git a/lib/celluloid/zmq/socket.rb b/lib/celluloid/zmq/socket.rb new file mode 100644 index 0000000..e250e27 --- /dev/null +++ b/lib/celluloid/zmq/socket.rb @@ -0,0 +1,75 @@ +module Celluloid + module ZMQ + class Socket + extend Forwardable + def_delegator ZMQ, :result_ok? + # Create a new socket + def initialize(type) + @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase) + @linger = 0 + end + attr_reader :linger + + # Connect to the given 0MQ address + # Address should be in the form: tcp://1.2.3.4:5678/ + def connect(addr) + unless result_ok? @socket.connect addr + raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}" + end + true + end + + def linger=(value) + @linger = value || -1 + + unless result_ok? @socket.setsockopt(::ZMQ::LINGER, value) + raise IOError, "couldn't set linger: #{::ZMQ::Util.error_string}" + end + end + + def identity=(value) + unless result_ok? @socket.setsockopt(::ZMQ::IDENTITY, "#{value}") + raise IOError, "couldn't set identity: #{::ZMQ::Util.error_string}" + end + #de @socket.identity = value + end + + def identity + #de @socket.identity + get(::ZMQ::IDENTITY) + end + + def set(option, value, length = nil) + unless result_ok? @socket.setsockopt(option, value, length) + raise IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}" + end + end + + def get(option) + option_value = [] + + unless result_ok? @socket.getsockopt(option, option_value) + raise IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}" + end + + option_value[0] + end + + # Bind to the given 0MQ address + # Address should be in the form: tcp://1.2.3.4:5678/ + def bind(addr) + unless result_ok? @socket.bind(addr) + raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}" + end + end + + # Close the socket + def close + @socket.close + end + + # Hide ffi-rzmq internals + alias_method :inspect, :to_s + end + end +end diff --git a/lib/celluloid/zmq/socket/readable.rb b/lib/celluloid/zmq/socket/readable.rb new file mode 100644 index 0000000..b42e4eb --- /dev/null +++ b/lib/celluloid/zmq/socket/readable.rb @@ -0,0 +1,46 @@ +module Celluloid + module ZMQ + class Socket + # Readable 0MQ sockets have a read method + module Readable + extend Forwardable + def_delegator ZMQ, :result_ok? + + # always set LINGER on readable sockets + def bind(addr) + self.linger = @linger + super(addr) + end + + def connect(addr) + self.linger = @linger + super(addr) + end + + # Read a message from the socket + def read(buffer = '') + ZMQ.wait_readable(@socket) if ZMQ.evented? + + unless result_ok? @socket.recv_string buffer + raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}" + end + buffer + end + + # Multiparts message ? + def_delegator :@socket, :more_parts? + + # Reads a multipart message, stores it into the given buffer and returns + # the buffer. + def read_multipart(buffer = []) + ZMQ.wait_readable(@socket) if ZMQ.evented? + + unless result_ok? @socket.recv_strings buffer + raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}" + end + buffer + end + end + end + end +end diff --git a/lib/celluloid/zmq/socket/types.rb b/lib/celluloid/zmq/socket/types.rb new file mode 100644 index 0000000..6a61b5e --- /dev/null +++ b/lib/celluloid/zmq/socket/types.rb @@ -0,0 +1,104 @@ +module Celluloid + module ZMQ + class Socket + # ReqSockets are the counterpart of RepSockets (REQ/REP) + class Req < Socket + include Readable + include Writable + + def initialize + super :req + end + end + + # RepSockets are the counterpart of ReqSockets (REQ/REP) + class Rep < Socket + include Readable + include Writable + + def initialize + super :rep + end + end + + # DealerSockets are like ReqSockets but more flexible + class Dealer < Socket + include Readable + include Writable + + def initialize + super :dealer + end + end + + # RouterSockets are like RepSockets but more flexible + class Router < Socket + include Readable + include Writable + + def initialize + super :router + end + end + + # PushSockets are the counterpart of PullSockets (PUSH/PULL) + class Push < Socket + include Writable + + def initialize + super :push + end + end + + # PullSockets are the counterpart of PushSockets (PUSH/PULL) + class Pull < Socket + include Readable + + def initialize + super :pull + end + end + + # PubSockets are the counterpart of SubSockets (PUB/SUB) + class Pub < Socket + include Writable + + def initialize + super :pub + end + end + + # XPubSockets are just like PubSockets but reading from them gives you the + # subscription/unsubscription channels as they're joined/left. + class XPub < Socket + include Writable + include Readable + + def initialize + super :xpub + end + end + + # SubSockets are the counterpart of PubSockets (PUB/SUB) + class Sub < Socket + include Readable + + def initialize + super :sub + end + + def subscribe(topic) + unless result_ok? @socket.setsockopt(::ZMQ::SUBSCRIBE, topic) + raise IOError, "couldn't set subscribe: #{::ZMQ::Util.error_string}" + end + end + + def unsubscribe(topic) + unless result_ok? @socket.setsockopt(::ZMQ::UNSUBSCRIBE, topic) + raise IOError, "couldn't set unsubscribe: #{::ZMQ::Util.error_string}" + end + end + end + end + end +end diff --git a/lib/celluloid/zmq/socket/writable.rb b/lib/celluloid/zmq/socket/writable.rb new file mode 100644 index 0000000..2b98a6b --- /dev/null +++ b/lib/celluloid/zmq/socket/writable.rb @@ -0,0 +1,30 @@ +module Celluloid + module ZMQ + class Socket + # Writable 0MQ sockets have a send method + module Writable + extend Forwardable + def_delegator ZMQ, :result_ok? + # Send a message to the socket + def write(*messages) + unless result_ok? @socket.send_strings(messages.flatten) + raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}" + end + + messages + end + alias_method :<<, :write + alias_method :send, :write # deprecated + + def write_to(address, message) + error = [IOError, "Failure sending part of message."] + raise *error unless result_ok? @socket.send_string("#{address}", ::ZMQ::SNDMORE) + raise *error unless result_ok? @socket.send_string("", ::ZMQ::SNDMORE) + raise *error unless result_ok? @socket.send_string(message) + message + end + + end + end + end +end diff --git a/lib/celluloid/zmq/sockets.rb b/lib/celluloid/zmq/sockets.rb deleted file mode 100644 index bde1123..0000000 --- a/lib/celluloid/zmq/sockets.rb +++ /dev/null @@ -1,222 +0,0 @@ -module Celluloid - module ZMQ - class Socket - # Create a new socket - def initialize(type) - @socket = Celluloid::ZMQ.context.socket ::ZMQ.const_get(type.to_s.upcase) - @linger = 0 - end - attr_reader :linger - - # Connect to the given 0MQ address - # Address should be in the form: tcp://1.2.3.4:5678/ - def connect(addr) - unless ::ZMQ::Util.resultcode_ok? @socket.connect addr - raise IOError, "error connecting to #{addr}: #{::ZMQ::Util.error_string}" - end - true - end - - def linger=(value) - @linger = value || -1 - - unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::LINGER, value) - raise IOError, "couldn't set linger: #{::ZMQ::Util.error_string}" - end - end - - def identity=(value) - @socket.identity = value - end - - def identity - @socket.identity - end - - def set(option, value, length = nil) - unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(option, value, length) - raise IOError, "couldn't set value for option #{option}: #{::ZMQ::Util.error_string}" - end - end - - def get(option) - option_value = [] - - unless ::ZMQ::Util.resultcode_ok? @socket.getsockopt(option, option_value) - raise IOError, "couldn't get value for option #{option}: #{::ZMQ::Util.error_string}" - end - - option_value[0] - end - - # Bind to the given 0MQ address - # Address should be in the form: tcp://1.2.3.4:5678/ - def bind(addr) - unless ::ZMQ::Util.resultcode_ok? @socket.bind(addr) - raise IOError, "couldn't bind to #{addr}: #{::ZMQ::Util.error_string}" - end - end - - # Close the socket - def close - @socket.close - end - - # Hide ffi-rzmq internals - alias_method :inspect, :to_s - end - - # Readable 0MQ sockets have a read method - module ReadableSocket - extend Forwardable - - # always set LINGER on readable sockets - def bind(addr) - self.linger = @linger - super(addr) - end - - def connect(addr) - self.linger = @linger - super(addr) - end - - # Read a message from the socket - def read(buffer = '') - ZMQ.wait_readable(@socket) if ZMQ.evented? - - unless ::ZMQ::Util.resultcode_ok? @socket.recv_string buffer - raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}" - end - buffer - end - - # Multiparts message ? - def_delegator :@socket, :more_parts? - - # Reads a multipart message, stores it into the given buffer and returns - # the buffer. - def read_multipart(buffer = []) - ZMQ.wait_readable(@socket) if ZMQ.evented? - - unless ::ZMQ::Util.resultcode_ok? @socket.recv_strings buffer - raise IOError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}" - end - buffer - end - end - - # Writable 0MQ sockets have a send method - module WritableSocket - # Send a message to the socket - def write(*messages) - unless ::ZMQ::Util.resultcode_ok? @socket.send_strings messages.flatten - raise IOError, "error sending 0MQ message: #{::ZMQ::Util.error_string}" - end - - messages - end - alias_method :<<, :write - alias_method :send, :write # deprecated - end - - # ReqSockets are the counterpart of RepSockets (REQ/REP) - class ReqSocket < Socket - include ReadableSocket - include WritableSocket - - def initialize - super :req - end - end - - # RepSockets are the counterpart of ReqSockets (REQ/REP) - class RepSocket < Socket - include ReadableSocket - include WritableSocket - - def initialize - super :rep - end - end - - # DealerSockets are like ReqSockets but more flexible - class DealerSocket < Socket - include ReadableSocket - include WritableSocket - - def initialize - super :dealer - end - end - - # RouterSockets are like RepSockets but more flexible - class RouterSocket < Socket - include ReadableSocket - include WritableSocket - - def initialize - super :router - end - end - - # PushSockets are the counterpart of PullSockets (PUSH/PULL) - class PushSocket < Socket - include WritableSocket - - def initialize - super :push - end - end - - # PullSockets are the counterpart of PushSockets (PUSH/PULL) - class PullSocket < Socket - include ReadableSocket - - def initialize - super :pull - end - end - - # PubSockets are the counterpart of SubSockets (PUB/SUB) - class PubSocket < Socket - include WritableSocket - - def initialize - super :pub - end - end - - # XPubSockets are just like PubSockets but reading from them gives you the - # subscription/unsubscription channels as they're joined/left. - class XPubSocket < Socket - include WritableSocket - include ReadableSocket - - def initialize - super :xpub - end - end - - # SubSockets are the counterpart of PubSockets (PUB/SUB) - class SubSocket < Socket - include ReadableSocket - - def initialize - super :sub - end - - def subscribe(topic) - unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::SUBSCRIBE, topic) - raise IOError, "couldn't set subscribe: #{::ZMQ::Util.error_string}" - end - end - - def unsubscribe(topic) - unless ::ZMQ::Util.resultcode_ok? @socket.setsockopt(::ZMQ::UNSUBSCRIBE, topic) - raise IOError, "couldn't set unsubscribe: #{::ZMQ::Util.error_string}" - end - end - end - end -end diff --git a/lib/celluloid/zmq/version.rb b/lib/celluloid/zmq/version.rb index 61c0c4e..f118e47 100644 --- a/lib/celluloid/zmq/version.rb +++ b/lib/celluloid/zmq/version.rb @@ -1,5 +1,5 @@ module Celluloid module ZMQ - VERSION = "0.16.1" + VERSION = "0.17.0" end end diff --git a/lib/celluloid/zmq/waker.rb b/lib/celluloid/zmq/waker.rb index ed16b39..e1b8591 100644 --- a/lib/celluloid/zmq/waker.rb +++ b/lib/celluloid/zmq/waker.rb @@ -7,6 +7,8 @@ module ZMQ # Works like a ConditionVariable, except it's implemented as a ZMQ socket # so that it can be multiplexed alongside other ZMQ sockets class Waker + extend Forwardable + def_delegator ZMQ, :result_ok? PAYLOAD = "\0" # the payload doesn't matter, it's just a signal def initialize @@ -23,7 +25,7 @@ def initialize # Wakes up the thread that is waiting for this Waker def signal @sender_lock.synchronize do - unless ::ZMQ::Util.resultcode_ok? @sender.send_string PAYLOAD + unless result_ok? @sender.send_string PAYLOAD raise DeadWakerError, "error sending 0MQ message: #{::ZMQ::Util.error_string}" end end @@ -39,7 +41,7 @@ def wait message = '' rc = @receiver.recv_string message - unless ::ZMQ::Util.resultcode_ok? rc and message == PAYLOAD + unless result_ok? rc and message == PAYLOAD raise DeadWakerError, "error receiving ZMQ string: #{::ZMQ::Util.error_string}" end end diff --git a/spec/celluloid/zmq/actor_spec.rb b/spec/celluloid/zmq/actor_spec.rb index 0f8173b..3124f09 100644 --- a/spec/celluloid/zmq/actor_spec.rb +++ b/spec/celluloid/zmq/actor_spec.rb @@ -2,4 +2,4 @@ RSpec.describe Celluloid::ZMQ do it_behaves_like "a Celluloid Actor", Celluloid::ZMQ -end +end \ No newline at end of file diff --git a/spec/celluloid/zmq/socket_spec.rb b/spec/celluloid/zmq/socket_spec.rb index 2fd8dbc..f33481c 100644 --- a/spec/celluloid/zmq/socket_spec.rb +++ b/spec/celluloid/zmq/socket_spec.rb @@ -3,7 +3,7 @@ RSpec.describe Celluloid::ZMQ::Socket, actor_system: :global do it "allows setting and getting ZMQ options on the socket" do - socket = Celluloid::ZMQ::RepSocket.new + socket = Celluloid::ZMQ::Socket::Rep.new socket.set(::ZMQ::IDENTITY, "Identity") identity = socket.get(::ZMQ::IDENTITY) diff --git a/spec/celluloid/zmq_spec.rb b/spec/celluloid/zmq_spec.rb index 69e6c67..920eb1a 100644 --- a/spec/celluloid/zmq_spec.rb +++ b/spec/celluloid/zmq_spec.rb @@ -48,7 +48,7 @@ def bind(socket, index=0) end end - describe Celluloid::ZMQ::RepSocket do + describe Celluloid::ZMQ::Socket::Rep do let(:actor) do Class.new do include Celluloid::ZMQ @@ -56,7 +56,7 @@ def bind(socket, index=0) finalizer :close_socket def initialize(index) - @socket = Celluloid::ZMQ::RepSocket.new + @socket = Celluloid::ZMQ::Socket::Rep.new @socket.connect("inproc://celluloid-spec-#{index}") end @@ -94,7 +94,7 @@ def close_socket end end - describe Celluloid::ZMQ::ReqSocket do + describe Celluloid::ZMQ::Socket::Req do let(:actor) do Class.new do include Celluloid::ZMQ @@ -102,7 +102,7 @@ def close_socket finalizer :close_socket def initialize(index) - @socket = Celluloid::ZMQ::ReqSocket.new + @socket = Celluloid::ZMQ::Socket::Req.new @socket.connect("inproc://celluloid-spec-#{index}") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f6e8a79..242a62a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,26 @@ require 'coveralls' Coveralls.wear! +require 'rubygems' require 'bundler/setup' require 'celluloid/zmq' +require 'celluloid/rspec' + +module CelluloidSpecs + # Require a file from Celluloid gem 'spec' location directly + def self.require(path) + celluloid = Pathname(Gem::Specification.find_all_by_name('celluloid').first.full_gem_path) + full_path = celluloid + 'spec' + path + Kernel.require(full_path.to_s) + end + + def self.included_module + Celluloid::ZMQ + end + + # Timer accuracy enforced by the tests (50ms) + TIMER_QUANTUM = 0.05 +end logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a') Celluloid.logger = Logger.new(logfile) @@ -19,4 +37,9 @@ Celluloid.shutdown Celluloid::ZMQ.terminate end + + config.before(:each) do |example| + @fake_logger = Specs::FakeLogger.new(Celluloid.logger, example.description) + stub_const('Celluloid::Internals::Logger', @fake_logger) + end end