File: reqrep_spec.rb

package info (click to toggle)
ruby-ffi-rzmq 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 380 kB
  • ctags: 204
  • sloc: ruby: 2,945; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,373 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

require File.join(File.dirname(__FILE__), %w[spec_helper])

module ZMQ


  describe Socket do

    context "when running ping pong" do
      include APIHelper

      let(:string) { "booga-booga" }

      # reset sockets each time because we only send 1 message which leaves
      # the REQ socket in a bad state. It cannot send again unless we were to
      # send a reply with the REP and read it.
      before(:each) do
        @context = ZMQ::Context.new
        poller_setup

        endpoint = "inproc://reqrep_test"
        @ping = @context.socket ZMQ::REQ
        @pong = @context.socket ZMQ::REP
        @pong.bind(endpoint)
        connect_to_inproc(@ping, endpoint)
      end

      after(:each) do
        @ping.close
        @pong.close
        @context.terminate
      end
      
      def send_ping(string)
        @ping.send_string string
        received_message = ''
        rc = @pong.recv_string received_message
        [rc, received_message]
      end

      it "should receive an exact string copy of the string message sent" do
        rc, received_message = send_ping(string)
        received_message.should == string
      end
      
      it "should generate a EFSM error when sending via the REQ socket twice in a row without an intervening receive operation" do
        send_ping(string)
        rc = @ping.send_string(string)
        rc.should == -1
        Util.errno.should == ZMQ::EFSM
      end

      it "should receive an exact copy of the sent message using Message objects directly" do
        received_message = Message.new

        rc = @ping.sendmsg(Message.new(string))
        rc.should == string.size
        rc = @pong.recvmsg received_message
        rc.should == string.size

        received_message.copy_out_string.should == string
      end

      it "should receive an exact copy of the sent message using Message objects directly in non-blocking mode" do
        sent_message = Message.new string
        received_message = Message.new

        poll_it_for_read(@pong) do
          rc = @ping.sendmsg(Message.new(string), ZMQ::DONTWAIT)
          rc.should == string.size
        end
        
        rc = @pong.recvmsg received_message, ZMQ::DONTWAIT
        rc.should == string.size

        received_message.copy_out_string.should == string
      end

    end # context ping-pong


  end # describe


end # module ZMQ