Permalink
Browse files

Added Specs for Reply inside a thread

  • Loading branch information...
krakatoa committed Aug 24, 2012
1 parent f8223a0 commit 387b6b2aef6db05e8538b9adc8daef55620ca06d
Showing with 45 additions and 0 deletions.
  1. +45 −0 spec/request_spec.rb
View
@@ -135,4 +135,49 @@
sleep 1
end
end
+
+ context "not under EM, Reply inside Thread/EM" do
+ before(:each) do
+ @request = MaZMQ::Request.new
+ end
+
+ context 'when requesting to a listening Reply' do
+ before do
+ @reply_thread = Thread.new {
+ EM.run do
+ @reply = MaZMQ::Reply.new
+ @reply.bind :tcp, "127.0.0.1", 5235
+ @reply.on_read { |msg|
+ @reply.send_string("response")
+ @reply.close
+ EM.stop
+ }
+ end
+ }
+ sleep 1
+ @request.connect :tcp, '127.0.0.1', 5235
+ end
+
+ it "should receive a response" do
+ @request.send_string("request").should == :sending; sleep 1
+
+ @request.recv_string.should == "response"
+ end
+
+ it "should change its state" do
+ @request.state.should == :idle
+
+ @request.send_string("request"); sleep 1
+ @request.state.should == :sending
+
+ @request.recv_string
+ @request.state.should == :idle
+ end
+ end
+
+ after(:each) do
+ @request.close
+ sleep 1
+ end
+ end
end

0 comments on commit 387b6b2

Please sign in to comment.