Skip to content

Commit

Permalink
Add spec which tests writing to sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Jan 30, 2014
1 parent df09da2 commit d6867cd
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/celluloid/zmq_spec.rb
Expand Up @@ -106,4 +106,58 @@ def close_socket
result.value.should eq("hello world")
end
end

describe Celluloid::ZMQ::ReqSocket do
let(:actor) do
Class.new do
include Celluloid::ZMQ

finalizer :close_socket

def initialize(port)
@socket = Celluloid::ZMQ::ReqSocket.new
@socket.connect("tcp://127.0.0.1:#{port}")
end

def say_hi
"Hi!"
end

def send(message)
@socket.write(message)
true
end

def close_socket
@socket.close
end
end
end

it "sends messages" do
client = bind(Celluloid::ZMQ.context.socket(::ZMQ::REP))
server = actor.new(ports[0])

server.send("hello world")

message = ""
client.recv_string(message)
message.should eq("hello world")
end

it "suspends actor while waiting for message to be sent" do
client = bind(Celluloid::ZMQ.context.socket(::ZMQ::REP))
server = actor.new(ports[0])

result = server.future.send("hello world")

server.say_hi.should eq("Hi!")

message = ""
client.recv_string(message)
message.should eq("hello world")

result.value.should be_true
end
end
end

0 comments on commit d6867cd

Please sign in to comment.