ffi-rzmq 2.0.0 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +5 -6
- data/AUTHORS.txt +3 -1
- data/History.txt +60 -0
- data/README.rdoc +65 -25
- data/Rakefile +15 -0
- data/examples/repreq_over_curve.rb +60 -0
- data/ffi-rzmq.gemspec +2 -2
- data/lib/ffi-rzmq/context.rb +3 -3
- data/lib/ffi-rzmq/exceptions.rb +3 -0
- data/lib/ffi-rzmq/poll_item.rb +0 -1
- data/lib/ffi-rzmq/socket.rb +3 -4
- data/lib/ffi-rzmq/util.rb +17 -0
- data/lib/ffi-rzmq/version.rb +1 -1
- data/lib/ffi-rzmq.rb +2 -1
- data/lib/io_extensions.rb +1 -1
- data/spec/context_spec.rb +16 -16
- data/spec/device_spec.rb +6 -6
- data/spec/message_spec.rb +13 -13
- data/spec/multipart_spec.rb +11 -11
- data/spec/nonblocking_recv_spec.rb +15 -15
- data/spec/poll_spec.rb +49 -49
- data/spec/pushpull_spec.rb +8 -8
- data/spec/reqrep_spec.rb +9 -9
- data/spec/socket_spec.rb +77 -77
- data/spec/support/generate_keys_and_certs.rb +41 -0
- data/spec/support/test.crt +26 -13
- data/spec/support/test.key +49 -13
- data/spec/util_spec.rb +29 -0
- data/travis_build_script.sh +27 -0
- metadata +24 -18
data/spec/message_spec.rb
CHANGED
@@ -9,12 +9,12 @@ module ZMQ
|
|
9
9
|
context "when initializing with an argument" do
|
10
10
|
|
11
11
|
it "calls zmq_msg_init_data()" do
|
12
|
-
LibZMQ.
|
12
|
+
expect(LibZMQ).to receive(:zmq_msg_init_data)
|
13
13
|
message = Message.new "text"
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should *not* define a finalizer on this object" do
|
17
|
-
ObjectSpace.
|
17
|
+
expect(ObjectSpace).not_to receive(:define_finalizer)
|
18
18
|
Message.new "text"
|
19
19
|
end
|
20
20
|
end # context initializing with arg
|
@@ -22,12 +22,12 @@ module ZMQ
|
|
22
22
|
context "when initializing *without* an argument" do
|
23
23
|
|
24
24
|
it "calls zmq_msg_init()" do
|
25
|
-
LibZMQ.
|
25
|
+
expect(LibZMQ).to receive(:zmq_msg_init).and_return(0)
|
26
26
|
message = Message.new
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should *not* define a finalizer on this object" do
|
30
|
-
ObjectSpace.
|
30
|
+
expect(ObjectSpace).not_to receive(:define_finalizer)
|
31
31
|
Message.new "text"
|
32
32
|
end
|
33
33
|
end # context initializing with arg
|
@@ -37,14 +37,14 @@ module ZMQ
|
|
37
37
|
it "calls zmq_msg_init_data()" do
|
38
38
|
message = Message.new "text"
|
39
39
|
|
40
|
-
LibZMQ.
|
40
|
+
expect(LibZMQ).to receive(:zmq_msg_init_data)
|
41
41
|
message.copy_in_string("new text")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "correctly finds the length of binary data by ignoring encoding" do
|
45
45
|
message = Message.new
|
46
46
|
message.copy_in_string("\x83\x6e\x04\x00\x00\x44\xd1\x81")
|
47
|
-
message.size.
|
47
|
+
expect(message.size).to eq(8)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -54,7 +54,7 @@ module ZMQ
|
|
54
54
|
message = Message.new "text"
|
55
55
|
copy = Message.new
|
56
56
|
|
57
|
-
LibZMQ.
|
57
|
+
expect(LibZMQ).to receive(:zmq_msg_copy)
|
58
58
|
copy.copy(message)
|
59
59
|
end
|
60
60
|
end # context copy
|
@@ -65,7 +65,7 @@ module ZMQ
|
|
65
65
|
message = Message.new "text"
|
66
66
|
copy = Message.new
|
67
67
|
|
68
|
-
LibZMQ.
|
68
|
+
expect(LibZMQ).to receive(:zmq_msg_move)
|
69
69
|
copy.move(message)
|
70
70
|
end
|
71
71
|
end # context move
|
@@ -75,7 +75,7 @@ module ZMQ
|
|
75
75
|
it "calls zmq_msg_size()" do
|
76
76
|
message = Message.new "text"
|
77
77
|
|
78
|
-
LibZMQ.
|
78
|
+
expect(LibZMQ).to receive(:zmq_msg_size)
|
79
79
|
message.size
|
80
80
|
end
|
81
81
|
end # context size
|
@@ -85,7 +85,7 @@ module ZMQ
|
|
85
85
|
it "calls zmq_msg_data()" do
|
86
86
|
message = Message.new "text"
|
87
87
|
|
88
|
-
LibZMQ.
|
88
|
+
expect(LibZMQ).to receive(:zmq_msg_data)
|
89
89
|
message.data
|
90
90
|
end
|
91
91
|
end # context data
|
@@ -95,7 +95,7 @@ module ZMQ
|
|
95
95
|
it "calls zmq_msg_close() the first time" do
|
96
96
|
message = Message.new "text"
|
97
97
|
|
98
|
-
LibZMQ.
|
98
|
+
expect(LibZMQ).to receive(:zmq_msg_close)
|
99
99
|
message.close
|
100
100
|
end
|
101
101
|
|
@@ -103,7 +103,7 @@ module ZMQ
|
|
103
103
|
message = Message.new "text"
|
104
104
|
message.close
|
105
105
|
|
106
|
-
LibZMQ.
|
106
|
+
expect(LibZMQ).not_to receive(:zmq_msg_close)
|
107
107
|
message.close
|
108
108
|
end
|
109
109
|
end # context close
|
@@ -116,7 +116,7 @@ module ZMQ
|
|
116
116
|
context "when initializing with an argument" do
|
117
117
|
|
118
118
|
it "should define a finalizer on this object" do
|
119
|
-
ObjectSpace.
|
119
|
+
expect(ObjectSpace).to receive(:define_finalizer)
|
120
120
|
ManagedMessage.new "text"
|
121
121
|
end
|
122
122
|
end # context initializing
|
data/spec/multipart_spec.rb
CHANGED
@@ -29,7 +29,7 @@ module ZMQ
|
|
29
29
|
sleep 1
|
30
30
|
strings = []
|
31
31
|
rc = @receiver.recv_strings(strings)
|
32
|
-
strings.
|
32
|
+
expect(strings).to eq(data)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -56,12 +56,12 @@ module ZMQ
|
|
56
56
|
@req.send_strings(req_data)
|
57
57
|
strings = []
|
58
58
|
rc = @rep.recv_strings(strings)
|
59
|
-
strings.
|
59
|
+
expect(strings).to eq(req_data)
|
60
60
|
|
61
61
|
@rep.send_strings(rep_data)
|
62
62
|
strings = []
|
63
63
|
rc = @req.recv_strings(strings)
|
64
|
-
strings.
|
64
|
+
expect(strings).to eq(rep_data)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should be delivered between REQ and REP returning an array of messages" do
|
@@ -71,14 +71,14 @@ module ZMQ
|
|
71
71
|
messages = []
|
72
72
|
rc = @rep.recvmsgs(messages)
|
73
73
|
messages.each_with_index do |message, index|
|
74
|
-
message.copy_out_string.
|
74
|
+
expect(message.copy_out_string).to eq(req_data[index])
|
75
75
|
end
|
76
76
|
|
77
77
|
@rep.send_strings(rep_data)
|
78
78
|
messages = []
|
79
79
|
rc = @req.recvmsgs(messages)
|
80
80
|
messages.each_with_index do |message, index|
|
81
|
-
message.copy_out_string.
|
81
|
+
expect(message.copy_out_string).to eq(rep_data[index])
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -106,12 +106,12 @@ module ZMQ
|
|
106
106
|
@req.send_string(req_data)
|
107
107
|
strings = []
|
108
108
|
rc = @rep.recv_strings(strings)
|
109
|
-
strings.
|
109
|
+
expect(strings).to eq([ @req.identity, "", "hello" ])
|
110
110
|
|
111
111
|
@rep.send_strings(rep_data)
|
112
112
|
string = ''
|
113
113
|
rc = @req.recv_string(string)
|
114
|
-
string.
|
114
|
+
expect(string).to eq(rep_data.last)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should be delivered between REQ and REP returning an array of messages with an empty string as the envelope delimiter" do
|
@@ -120,14 +120,14 @@ module ZMQ
|
|
120
120
|
@req.send_string(req_data)
|
121
121
|
msgs = []
|
122
122
|
rc = @rep.recvmsgs(msgs)
|
123
|
-
msgs[0].copy_out_string.
|
124
|
-
msgs[1].copy_out_string.
|
125
|
-
msgs[2].copy_out_string.
|
123
|
+
expect(msgs[0].copy_out_string).to eq(@req.identity)
|
124
|
+
expect(msgs[1].copy_out_string).to eq("")
|
125
|
+
expect(msgs[2].copy_out_string).to eq("hello")
|
126
126
|
|
127
127
|
@rep.send_strings(rep_data)
|
128
128
|
msgs = []
|
129
129
|
rc = @req.recvmsgs(msgs)
|
130
|
-
msgs[0].copy_out_string.
|
130
|
+
expect(msgs[0].copy_out_string).to eq(rep_data.last)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -13,19 +13,19 @@ module ZMQ
|
|
13
13
|
it "returns -1 when there are no messages to read" do
|
14
14
|
array = []
|
15
15
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
16
|
-
Util.resultcode_ok?(rc).
|
16
|
+
expect(Util.resultcode_ok?(rc)).to eq(false)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "gets EAGAIN when there are no messages to read" do
|
20
20
|
array = []
|
21
21
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
22
|
-
ZMQ::Util.errno.
|
22
|
+
expect(ZMQ::Util.errno).to eq(ZMQ::EAGAIN)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "returns the given array unmodified when there are no messages to read" do
|
26
26
|
array = []
|
27
27
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
28
|
-
array.size.
|
28
|
+
expect(array.size).to eq(0)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -35,26 +35,26 @@ module ZMQ
|
|
35
35
|
it "read the single message and returns a successful result code" do
|
36
36
|
poll_it_for_read(@receiver) do
|
37
37
|
rc = @sender.send_string('test')
|
38
|
-
Util.resultcode_ok?(rc).
|
38
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
39
39
|
end
|
40
40
|
|
41
41
|
array = []
|
42
42
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
43
|
-
Util.resultcode_ok?(rc).
|
44
|
-
array.size.
|
43
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
44
|
+
expect(array.size).to eq(1)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "read all message parts transmitted and returns a successful result code" do
|
48
48
|
poll_it_for_read(@receiver) do
|
49
49
|
strings = Array.new(10, 'test')
|
50
50
|
rc = @sender.send_strings(strings)
|
51
|
-
Util.resultcode_ok?(rc).
|
51
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
52
52
|
end
|
53
53
|
|
54
54
|
array = []
|
55
55
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
56
|
-
Util.resultcode_ok?(rc).
|
57
|
-
array.size.
|
56
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
57
|
+
expect(array.size).to eq(10)
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
@@ -64,26 +64,26 @@ module ZMQ
|
|
64
64
|
it "read the single message and returns a successful result code" do
|
65
65
|
poll_it_for_read(@receiver) do
|
66
66
|
rc = @sender.send_string('test')
|
67
|
-
Util.resultcode_ok?(rc).
|
67
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
68
68
|
end
|
69
69
|
|
70
70
|
array = []
|
71
71
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
72
|
-
Util.resultcode_ok?(rc).
|
73
|
-
array.size.
|
72
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
73
|
+
expect(array.size).to eq(1 + 1) # extra 1 for envelope
|
74
74
|
end
|
75
75
|
|
76
76
|
it "read all message parts transmitted and returns a successful result code" do
|
77
77
|
poll_it_for_read(@receiver) do
|
78
78
|
strings = Array.new(10, 'test')
|
79
79
|
rc = @sender.send_strings(strings)
|
80
|
-
Util.resultcode_ok?(rc).
|
80
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
81
81
|
end
|
82
82
|
|
83
83
|
array = []
|
84
84
|
rc = @receiver.recvmsgs(array, ZMQ::DONTWAIT)
|
85
|
-
Util.resultcode_ok?(rc).
|
86
|
-
array.size.
|
85
|
+
expect(Util.resultcode_ok?(rc)).to eq(true)
|
86
|
+
expect(array.size).to eq(10 + 1) # add 1 for the envelope
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
data/spec/poll_spec.rb
CHANGED
@@ -8,7 +8,7 @@ module ZMQ
|
|
8
8
|
include APIHelper
|
9
9
|
|
10
10
|
it "should allocate a PollItems instance" do
|
11
|
-
PollItems.
|
11
|
+
expect(PollItems).to receive(:new)
|
12
12
|
Poller.new
|
13
13
|
end
|
14
14
|
|
@@ -23,30 +23,30 @@ module ZMQ
|
|
23
23
|
let(:fd) { 1 }
|
24
24
|
|
25
25
|
it "returns false when given a nil pollable" do
|
26
|
-
poller.register(nil, ZMQ::POLLIN).
|
26
|
+
expect(poller.register(nil, ZMQ::POLLIN)).to be_falsy
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns false when given 0 for +events+ (e.g. no registration)" do
|
30
|
-
poller.register(pollable, 0).
|
30
|
+
expect(poller.register(pollable, 0)).to be_falsy
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the default registered event value when given a valid pollable" do
|
34
|
-
poller.register(pollable).
|
34
|
+
expect(poller.register(pollable)).to eq(ZMQ::POLLIN | ZMQ::POLLOUT)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "returns the registered event value when given a pollable responding to socket (ZMQ::Socket)" do
|
38
|
-
pollable.
|
39
|
-
poller.register(pollable, ZMQ::POLLIN).
|
38
|
+
expect(pollable).to receive(:socket).and_return(socket)
|
39
|
+
expect(poller.register(pollable, ZMQ::POLLIN)).to eq ZMQ::POLLIN
|
40
40
|
end
|
41
41
|
|
42
42
|
it "returns the registered event value when given a pollable responding to file descriptor (IO, BasicSocket)" do
|
43
|
-
pollable.
|
44
|
-
poller.register(pollable, ZMQ::POLLIN).
|
43
|
+
expect(pollable).to receive(:posix_fileno).and_return(fd)
|
44
|
+
expect(poller.register(pollable, ZMQ::POLLIN)).to eq(ZMQ::POLLIN)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns the registered event value when given a pollable responding to io (SSLSocket)" do
|
48
|
-
pollable.
|
49
|
-
poller.register(pollable, ZMQ::POLLIN).
|
48
|
+
expect(pollable).to receive(:io).and_return(io)
|
49
|
+
expect(poller.register(pollable, ZMQ::POLLIN)).to eq(ZMQ::POLLIN)
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
@@ -60,49 +60,49 @@ module ZMQ
|
|
60
60
|
let(:fd) { 1 }
|
61
61
|
|
62
62
|
it "returns true when deregistered pollable from event" do
|
63
|
-
pollable.
|
63
|
+
expect(pollable).to receive(:socket).at_least(:once).and_return(socket)
|
64
64
|
poller.register(pollable)
|
65
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
65
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "returns false when pollable not registered" do
|
69
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
69
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(false)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "returns false when pollable not registered for deregistered event" do
|
73
|
-
pollable.
|
73
|
+
expect(pollable).to receive(:socket).at_least(:once).and_return(socket)
|
74
74
|
poller.register(pollable, ZMQ::POLLOUT)
|
75
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
75
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(false)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "deletes pollable when no events left" do
|
79
79
|
poller.register(pollable, ZMQ::POLLIN)
|
80
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
81
|
-
poller.size.
|
80
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
|
81
|
+
expect(poller.size).to eq 0
|
82
82
|
end
|
83
83
|
|
84
84
|
it "deletes closed pollable responding to socket (ZMQ::Socket)" do
|
85
|
-
pollable.
|
85
|
+
expect(pollable).to receive(:socket).and_return(socket)
|
86
86
|
poller.register(pollable)
|
87
|
-
pollable.
|
88
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
89
|
-
poller.size.
|
87
|
+
expect(pollable).to receive(:socket).and_return(nil)
|
88
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
|
89
|
+
expect(poller.size).to eq 0
|
90
90
|
end
|
91
91
|
|
92
92
|
it "deletes closed pollable responding to fileno (IO, BasicSocket)" do
|
93
|
-
pollable.
|
93
|
+
expect(pollable).to receive(:posix_fileno).and_return(fd)
|
94
94
|
poller.register(pollable)
|
95
|
-
pollable.
|
96
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
97
|
-
poller.size.
|
95
|
+
expect(pollable).to receive(:closed?).and_return(true)
|
96
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
|
97
|
+
expect(poller.size).to eq 0
|
98
98
|
end
|
99
99
|
|
100
100
|
it "deletes closed pollable responding to io (SSLSocket)" do
|
101
|
-
pollable.
|
101
|
+
expect(pollable).to receive(:io).at_least(:once).and_return(io)
|
102
102
|
poller.register(pollable)
|
103
|
-
io.
|
104
|
-
poller.deregister(pollable, ZMQ::POLLIN).
|
105
|
-
poller.size.
|
103
|
+
expect(io).to receive(:closed?).and_return(true)
|
104
|
+
expect(poller.deregister(pollable, ZMQ::POLLIN)).to eq(true)
|
105
|
+
expect(poller.size).to eq 0
|
106
106
|
end
|
107
107
|
|
108
108
|
end
|
@@ -123,7 +123,7 @@ module ZMQ
|
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should return false for an unregistered socket (i.e. not found)" do
|
126
|
-
@poller.delete(@socket).
|
126
|
+
expect(@poller.delete(@socket)).to eq(false)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "returns true for a sucessfully deleted socket when only 1 is registered" do
|
@@ -131,7 +131,7 @@ module ZMQ
|
|
131
131
|
socket1.setsockopt(LINGER, 0)
|
132
132
|
|
133
133
|
@poller.register socket1
|
134
|
-
@poller.delete(socket1).
|
134
|
+
expect(@poller.delete(socket1)).to eq(true)
|
135
135
|
socket1.close
|
136
136
|
end
|
137
137
|
|
@@ -143,7 +143,7 @@ module ZMQ
|
|
143
143
|
|
144
144
|
@poller.register socket1
|
145
145
|
@poller.register socket2
|
146
|
-
@poller.delete(socket2).
|
146
|
+
expect(@poller.delete(socket2)).to eq(true)
|
147
147
|
socket1.close
|
148
148
|
socket2.close
|
149
149
|
end
|
@@ -154,7 +154,7 @@ module ZMQ
|
|
154
154
|
|
155
155
|
@poller.register socket1
|
156
156
|
socket1.close
|
157
|
-
@poller.delete(socket1).
|
157
|
+
expect(@poller.delete(socket1)).to eq(true)
|
158
158
|
end
|
159
159
|
|
160
160
|
end
|
@@ -177,12 +177,12 @@ module ZMQ
|
|
177
177
|
after(:each) { @sockets.each(&:close) }
|
178
178
|
|
179
179
|
it "returns 0 when there are no sockets to poll" do
|
180
|
-
@poller.poll(100).
|
180
|
+
expect(@poller.poll(100)).to eq 0
|
181
181
|
end
|
182
182
|
|
183
183
|
it "returns 0 when there is a single socket to poll and no events" do
|
184
184
|
@poller.register(@sockets.first, 0)
|
185
|
-
@poller.poll(100).
|
185
|
+
expect(@poller.poll(100)).to eq 0
|
186
186
|
end
|
187
187
|
|
188
188
|
it "returns 1 when there is a read event on a socket" do
|
@@ -190,7 +190,7 @@ module ZMQ
|
|
190
190
|
@poller.register_readable(last)
|
191
191
|
|
192
192
|
first.send_string('test')
|
193
|
-
@poller.poll(1000).
|
193
|
+
expect(@poller.poll(1000)).to eq 1
|
194
194
|
end
|
195
195
|
|
196
196
|
it "returns 1 when there is a read event on one socket and the second socket has been removed from polling" do
|
@@ -200,7 +200,7 @@ module ZMQ
|
|
200
200
|
|
201
201
|
first.send_string('test')
|
202
202
|
@poller.deregister_writable(first)
|
203
|
-
@poller.poll(1000).
|
203
|
+
expect(@poller.poll(1000)).to eq 1
|
204
204
|
end
|
205
205
|
|
206
206
|
it "works with BasiSocket" do
|
@@ -214,12 +214,12 @@ module ZMQ
|
|
214
214
|
|
215
215
|
client.send("message", 0)
|
216
216
|
|
217
|
-
@poller.poll.
|
218
|
-
@poller.readables.
|
219
|
-
@poller.writables.
|
217
|
+
expect(@poller.poll).to eq 2
|
218
|
+
expect(@poller.readables).to eq [s]
|
219
|
+
expect(@poller.writables).to eq [client]
|
220
220
|
|
221
221
|
msg = s.read_nonblock(7)
|
222
|
-
msg.
|
222
|
+
expect(msg).to eq "message"
|
223
223
|
end
|
224
224
|
|
225
225
|
it "works with IO objects" do
|
@@ -229,12 +229,12 @@ module ZMQ
|
|
229
229
|
|
230
230
|
w.write("message")
|
231
231
|
|
232
|
-
@poller.poll.
|
233
|
-
@poller.readables.
|
234
|
-
@poller.writables.
|
232
|
+
expect(@poller.poll).to eq 2
|
233
|
+
expect(@poller.readables).to eq [r]
|
234
|
+
expect(@poller.writables).to eq [w]
|
235
235
|
|
236
236
|
msg = r.read(7)
|
237
|
-
msg.
|
237
|
+
expect(msg).to eq "message"
|
238
238
|
end
|
239
239
|
|
240
240
|
it "works with SSLSocket" do
|
@@ -262,12 +262,12 @@ module ZMQ
|
|
262
262
|
|
263
263
|
client.write("message")
|
264
264
|
|
265
|
-
@poller.poll.
|
266
|
-
@poller.readables.
|
267
|
-
@poller.writables.
|
265
|
+
expect(@poller.poll).to eq 2
|
266
|
+
expect(@poller.readables).to eq [s]
|
267
|
+
expect(@poller.writables).to eq [client]
|
268
268
|
|
269
269
|
msg = s.read(7)
|
270
|
-
msg.
|
270
|
+
expect(msg).to eq "message"
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
data/spec/pushpull_spec.rb
CHANGED
@@ -35,7 +35,7 @@ module ZMQ
|
|
35
35
|
received = ''
|
36
36
|
rc = @pull.recv_string received
|
37
37
|
assert_ok(rc)
|
38
|
-
received.
|
38
|
+
expect(received).to eq(string)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should receive an exact string copy of the message sent when receiving in non-blocking mode and using Message objects directly" do
|
@@ -44,12 +44,12 @@ module ZMQ
|
|
44
44
|
|
45
45
|
poll_it_for_read(@pull) do
|
46
46
|
rc = @push.sendmsg sent_message
|
47
|
-
rc.
|
47
|
+
expect(rc).to eq(string.size)
|
48
48
|
end
|
49
49
|
|
50
50
|
rc = @pull.recvmsg received_message, ZMQ::DONTWAIT
|
51
|
-
rc.
|
52
|
-
received_message.copy_out_string.
|
51
|
+
expect(rc).to eq(string.size)
|
52
|
+
expect(received_message.copy_out_string).to eq(string)
|
53
53
|
end
|
54
54
|
|
55
55
|
|
@@ -74,7 +74,7 @@ module ZMQ
|
|
74
74
|
thr = Thread.new do
|
75
75
|
buffer = ''
|
76
76
|
rc = socket.recv_string buffer
|
77
|
-
rc.
|
77
|
+
expect(rc).to eq(buffer.size)
|
78
78
|
mutex.synchronize { received << buffer }
|
79
79
|
socket.close
|
80
80
|
end
|
@@ -85,7 +85,7 @@ module ZMQ
|
|
85
85
|
|
86
86
|
threads.each {|t| t.join}
|
87
87
|
|
88
|
-
received.find_all {|r| r == string}.length.
|
88
|
+
expect(received.find_all {|r| r == string}.length).to eq(count)
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should receive a single message for each message sent when using a single shared socket protected by a mutex" do
|
@@ -99,7 +99,7 @@ module ZMQ
|
|
99
99
|
buffer = ''
|
100
100
|
rc = 0
|
101
101
|
mutex.synchronize { rc = @pull.recv_string buffer }
|
102
|
-
rc.
|
102
|
+
expect(rc).to eq(buffer.size)
|
103
103
|
mutex.synchronize { received << buffer }
|
104
104
|
end
|
105
105
|
end
|
@@ -108,7 +108,7 @@ module ZMQ
|
|
108
108
|
|
109
109
|
threads.each {|t| t.join}
|
110
110
|
|
111
|
-
received.find_all {|r| r == string}.length.
|
111
|
+
expect(received.find_all {|r| r == string}.length).to eq(count)
|
112
112
|
end
|
113
113
|
|
114
114
|
end # @context ping-pong
|
data/spec/reqrep_spec.rb
CHANGED
@@ -40,25 +40,25 @@ module ZMQ
|
|
40
40
|
|
41
41
|
it "should receive an exact string copy of the string message sent" do
|
42
42
|
rc, received_message = send_ping(string)
|
43
|
-
received_message.
|
43
|
+
expect(received_message).to eq(string)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should generate a EFSM error when sending via the REQ socket twice in a row without an intervening receive operation" do
|
47
47
|
send_ping(string)
|
48
48
|
rc = @ping.send_string(string)
|
49
|
-
rc.
|
50
|
-
Util.errno.
|
49
|
+
expect(rc).to eq(-1)
|
50
|
+
expect(Util.errno).to eq(ZMQ::EFSM)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should receive an exact copy of the sent message using Message objects directly" do
|
54
54
|
received_message = Message.new
|
55
55
|
|
56
56
|
rc = @ping.sendmsg(Message.new(string))
|
57
|
-
rc.
|
57
|
+
expect(rc).to eq(string.size)
|
58
58
|
rc = @pong.recvmsg received_message
|
59
|
-
rc.
|
59
|
+
expect(rc).to eq(string.size)
|
60
60
|
|
61
|
-
received_message.copy_out_string.
|
61
|
+
expect(received_message.copy_out_string).to eq(string)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should receive an exact copy of the sent message using Message objects directly in non-blocking mode" do
|
@@ -67,13 +67,13 @@ module ZMQ
|
|
67
67
|
|
68
68
|
poll_it_for_read(@pong) do
|
69
69
|
rc = @ping.sendmsg(Message.new(string), ZMQ::DONTWAIT)
|
70
|
-
rc.
|
70
|
+
expect(rc).to eq(string.size)
|
71
71
|
end
|
72
72
|
|
73
73
|
rc = @pong.recvmsg received_message, ZMQ::DONTWAIT
|
74
|
-
rc.
|
74
|
+
expect(rc).to eq(string.size)
|
75
75
|
|
76
|
-
received_message.copy_out_string.
|
76
|
+
expect(received_message.copy_out_string).to eq(string)
|
77
77
|
end
|
78
78
|
|
79
79
|
end # context ping-pong
|