ffi-rzmq 0.9.3 → 0.9.6

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.
data/lib/ffi-rzmq/util.rb CHANGED
@@ -1,10 +1,9 @@
1
1
 
2
2
  module ZMQ
3
3
 
4
- # These methods don't belong to any specific class. They get included
5
- # in the #Context, #Socket and #Poller classes.
4
+ # General utility methods.
6
5
  #
7
- module Util
6
+ class Util
8
7
 
9
8
  # Returns true when +rc+ is greater than or equal to 0, false otherwise.
10
9
  #
@@ -57,40 +56,15 @@ module ZMQ
57
56
 
58
57
  resultcode_ok?(rc) ? random : nil
59
58
  end
60
-
61
- # Returns the proper flag value for non-blocking regardless of 0mq
62
- # version.
63
- #
64
- if LibZMQ.version2?
65
-
66
- def self.nonblocking_flag
67
- NOBLOCK
68
- end
69
-
70
- elsif LibZMQ.version3?
71
-
72
- def self.nonblocking_flag
73
- DONTWAIT
74
- end
75
-
76
- end
77
-
78
-
79
- private
80
-
81
- # generate a random port between 10_000 and 65534
82
- def self.random_port
83
- rand(55534) + 10_000
84
- end
85
-
59
+
86
60
  # :doc:
87
- # Called by most library methods to verify there were no errors during
61
+ # Called to verify whether there were any errors during
88
62
  # operation. If any are found, raise the appropriate #ZeroMQError.
89
63
  #
90
64
  # When no error is found, this method returns +true+ which is behavior
91
65
  # used internally by #send and #recv.
92
66
  #
93
- def error_check source, result_code
67
+ def self.error_check source, result_code
94
68
  if -1 == result_code
95
69
  raise_error source, result_code
96
70
  end
@@ -99,23 +73,55 @@ module ZMQ
99
73
  true
100
74
  end
101
75
 
102
- def raise_error source, result_code
103
- if 'zmq_init' == source || 'zmq_socket' == source
76
+
77
+ private
78
+
79
+ # generate a random port between 10_000 and 65534
80
+ def self.random_port
81
+ rand(55534) + 10_000
82
+ end
83
+
84
+ def self.raise_error source, result_code
85
+ if context_error?(source)
104
86
  raise ContextError.new source, result_code, ZMQ::Util.errno, ZMQ::Util.error_string
105
87
 
106
- elsif ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move'].include?(source)
88
+ elsif message_error?(source)
107
89
  raise MessageError.new source, result_code, ZMQ::Util.errno, ZMQ::Util.error_string
108
90
 
109
91
  else
110
- puts "else"
111
92
  raise ZeroMQError.new source, result_code, -1,
112
93
  "Source [#{source}] does not match any zmq_* strings, rc [#{result_code}], errno [#{ZMQ::Util.errno}], error_string [#{ZMQ::Util.error_string}]"
113
94
  end
114
95
  end
115
96
 
116
- def eagain?
97
+ def self.eagain?
117
98
  EAGAIN == ZMQ::Util.errno
118
99
  end
100
+
101
+ if LibZMQ.version2?
102
+ def self.context_error?(source)
103
+ 'zmq_init' == source ||
104
+ 'zmq_socket' == source
105
+ end
106
+
107
+ def self.message_error?(source)
108
+ ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move'].include?(source)
109
+ end
110
+
111
+ elsif LibZMQ.version3?
112
+ def self.context_error?(source)
113
+ 'zmq_ctx_new' == source ||
114
+ 'zmq_ctx_set' == source ||
115
+ 'zmq_ctx_get' == source ||
116
+ 'zmq_ctx_destory' == source ||
117
+ 'zmq_ctx_set_monitor' == source
118
+ end
119
+
120
+ def self.message_error?(source)
121
+ ['zmq_msg_init', 'zmq_msg_init_data', 'zmq_msg_copy', 'zmq_msg_move', 'zmq_msg_close', 'zmq_msg_get',
122
+ 'zmq_msg_more', 'zmq_msg_recv', 'zmq_msg_send', 'zmq_msg_set'].include?(source)
123
+ end
124
+ end # if LibZMQ.version...?
119
125
 
120
126
  end # module Util
121
127
 
@@ -1,3 +1,3 @@
1
1
  module ZMQ
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.6"
3
3
  end
data/spec/context_spec.rb CHANGED
@@ -11,16 +11,12 @@ module ZMQ
11
11
  include APIHelper
12
12
 
13
13
  it "should return nil for negative io threads" do
14
- LibZMQ.stub(:zmq_init => nil)
15
14
  Context.create(-1).should be_nil
16
15
  end
17
16
 
18
17
  it "should default to requesting 1 i/o thread when no argument is passed" do
19
- ctx = mock('ctx')
20
- ctx.stub!(:null? => false)
21
- LibZMQ.should_receive(:zmq_init).with(1).and_return(ctx)
22
-
23
- Context.create
18
+ ctx = Context.create
19
+ ctx.io_threads.should == 1
24
20
  end
25
21
 
26
22
  it "should set the :pointer accessor to non-nil" do
@@ -48,17 +44,13 @@ module ZMQ
48
44
  context "when initializing with #new" do
49
45
  include APIHelper
50
46
 
51
- it "should raise an error for negative io threads" do
52
- LibZMQ.stub(:zmq_init => nil)
47
+ it "should raise a ContextError exception for negative io threads" do
53
48
  lambda { Context.new(-1) }.should raise_exception(ZMQ::ContextError)
54
49
  end
55
50
 
56
51
  it "should default to requesting 1 i/o thread when no argument is passed" do
57
- ctx = mock('ctx')
58
- ctx.stub!(:null? => false)
59
- LibZMQ.should_receive(:zmq_init).with(1).and_return(ctx)
60
-
61
- Context.new
52
+ ctx = Context.new
53
+ ctx.io_threads.should == 1
62
54
  end
63
55
 
64
56
  it "should set the :pointer accessor to non-nil" do
@@ -78,16 +70,28 @@ module ZMQ
78
70
 
79
71
  it "should define a finalizer on this object" do
80
72
  ObjectSpace.should_receive(:define_finalizer)
81
- ctx = Context.new 1
73
+ Context.new 1
82
74
  end
83
75
  end # context initializing
84
76
 
85
77
 
86
78
  context "when terminating" do
87
- it "should call zmq_term to terminate the library's context" do
79
+ it "should set the context to nil when terminating the library's context" do
88
80
  ctx = Context.new # can't use a shared context here because we are terminating it!
89
- LibZMQ.should_receive(:zmq_term).with(ctx.pointer).and_return(0)
90
81
  ctx.terminate
82
+ ctx.pointer.should be_nil
83
+ end
84
+
85
+ it "should call the correct library function to terminate the context" do
86
+ ctx = Context.new
87
+
88
+ if LibZMQ.version2?
89
+ LibZMQ.should_receive(:zmq_term).and_return(0)
90
+ ctx.terminate
91
+ else
92
+ LibZMQ.should_receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
93
+ ctx.terminate
94
+ end
91
95
  end
92
96
  end # context terminate
93
97
 
data/spec/device_spec.rb CHANGED
@@ -1,89 +1,77 @@
1
1
 
2
2
  require File.join(File.dirname(__FILE__), %w[spec_helper])
3
3
 
4
- if version2?
4
+ module ZMQ
5
+ describe Device do
6
+ include APIHelper
5
7
 
6
- module ZMQ
7
- describe Device do
8
- include APIHelper
8
+ before(:all) do
9
+ @ctx = Context.new
10
+ poller_setup
11
+ @front_endpoint = "inproc://device_front_test"
12
+ @back_endpoint = "inproc://device_back_test"
13
+ @mutex = Mutex.new
14
+ end
9
15
 
10
- before(:each) do
11
- @ctx = Context.new
12
- end
16
+ after(:all) do
17
+ @ctx.terminate
18
+ end
13
19
 
14
- after(:each) do
15
- @ctx.terminate
20
+ def create_streamer
21
+ @device_thread = false
22
+
23
+ Thread.new do
24
+ back = @ctx.socket(ZMQ::PULL)
25
+ back.bind(@back_endpoint)
26
+ front = @ctx.socket(ZMQ::PUSH)
27
+ front.bind(@front_endpoint)
28
+ @mutex.synchronize { @device_thread = true }
29
+ Device.new(ZMQ::STREAMER, back, front)
30
+ back.close
31
+ front.close
16
32
  end
17
-
18
- def create_streamer
19
- @backport = @frontport = nil
20
- Thread.new do
21
- back = @ctx.socket(ZMQ::PULL)
22
- @backport = bind_to_random_tcp_port(back)
23
- front = @ctx.socket(ZMQ::PUSH)
24
- @frontport = bind_to_random_tcp_port(front)
25
- Device.new(ZMQ::STREAMER, back, front)
26
- back.close
27
- front.close
33
+ end
34
+
35
+ def wait_for_device
36
+ loop do
37
+ can_break = false
38
+ @mutex.synchronize do
39
+ can_break = true if @device_thread
28
40
  end
29
- sleep 0.5
30
- end
31
-
32
- it "should create a streamer device without error given valid opts" do
33
- create_streamer
41
+ break if can_break
34
42
  end
35
-
36
- it "should be able to send messages through the device" do
37
- create_streamer
38
-
39
- pusher = @ctx.socket(ZMQ::PUSH)
40
- pusher.connect("tcp://127.0.0.1:#{@backport}")
41
- puller = @ctx.socket(ZMQ::PULL)
42
- puller.connect("tcp://127.0.0.1:#{@frontport}")
43
-
43
+ end
44
+
45
+ it "should create a device without error given valid opts" do
46
+ create_streamer
47
+ wait_for_device
48
+ end
49
+
50
+ it "should be able to send messages through the device" do
51
+ create_streamer
52
+ wait_for_device
53
+
54
+ pusher = @ctx.socket(ZMQ::PUSH)
55
+ connect_to_inproc(pusher, @back_endpoint)
56
+ puller = @ctx.socket(ZMQ::PULL)
57
+ connect_to_inproc(puller, @front_endpoint)
58
+
59
+ poll_it_for_read(puller) do
44
60
  pusher.send_string("hello")
45
- sleep 0.5
46
- res = ''
47
- rc = puller.recv_string(res, ZMQ::NOBLOCK)
48
- res.should == "hello"
49
-
50
- pusher.close
51
- puller.close
52
- sleep 0.5
53
- end
54
-
55
- it "should raise an ArgumentError when trying to pass non-socket objects into the device" do
56
- lambda {
57
- Device.new(ZMQ::STREAMER, 1,2)
58
- }.should raise_exception(ArgumentError)
59
- end
60
-
61
- it "should be able to create a forwarder device without error" do
62
- Thread.new do
63
- back = @ctx.socket(ZMQ::SUB)
64
- bind_to_random_tcp_port(back)
65
- front = @ctx.socket(ZMQ::PUB)
66
- bind_to_random_tcp_port(front)
67
- Device.new(ZMQ::FORWARDER, back, front)
68
- back.close
69
- front.close
70
- end
71
- sleep 0.5
72
- end
73
-
74
- it "should be able to create a queue device without error" do
75
- Thread.new do
76
- back = @ctx.socket(ZMQ::ROUTER)
77
- bind_to_random_tcp_port(back)
78
- front = @ctx.socket(ZMQ::DEALER)
79
- bind_to_random_tcp_port(front)
80
- Device.new(ZMQ::QUEUE, back, front)
81
- back.close
82
- front.close
83
- end
84
- sleep 0.5
85
61
  end
62
+
63
+ res = ''
64
+ rc = puller.recv_string(res, ZMQ::NonBlocking)
65
+ res.should == "hello"
66
+
67
+ pusher.close
68
+ puller.close
86
69
  end
87
- end
88
70
 
89
- end # if version2?
71
+ it "should raise an ArgumentError when trying to pass non-socket objects into the device" do
72
+ lambda {
73
+ Device.new(ZMQ::STREAMER, 1,2)
74
+ }.should raise_exception(ArgumentError)
75
+ end
76
+ end
77
+ end
@@ -55,7 +55,6 @@ module ZMQ
55
55
  end
56
56
  end
57
57
 
58
- if version2?
59
58
  context "with identity" do
60
59
  include APIHelper
61
60
 
@@ -104,59 +103,6 @@ module ZMQ
104
103
  end
105
104
  end
106
105
 
107
- elsif LibZMQ.version3? # version3
108
-
109
- context "with identity" do
110
- include APIHelper
111
-
112
- before(:each) do # was :all
113
- @rep = Socket.new(@ctx.pointer, ZMQ::ROUTER)
114
- port = bind_to_random_tcp_port(@rep)
115
-
116
- @req = Socket.new(@ctx.pointer, ZMQ::DEALER)
117
- @req.identity = 'foo'
118
- @req.connect("tcp://127.0.0.1:#{port}")
119
- end
120
-
121
- after(:each) do # was :all
122
- @req.close
123
- @rep.close
124
- end
125
-
126
- it "should be delivered between ROUTER and DEALER returning an array of strings" do
127
- req_data, rep_data = "hello", [ @req.identity, "ok" ]
128
-
129
- @req.send_string(req_data)
130
- strings = []
131
- rc = @rep.recv_strings(strings)
132
- strings.should == [ @req.identity, "hello" ]
133
-
134
- @rep.send_strings(rep_data)
135
- string = ''
136
- rc = @req.recv_string(string)
137
- string.should == rep_data.last
138
- end
139
-
140
- it "should be delivered between ROUTER and DEALER returning an array of messages" do
141
- req_data, rep_data = "hello", [ @req.identity, "ok" ]
142
-
143
- @req.send_string(req_data)
144
- msgs = []
145
- rc = @rep.recvmsgs(msgs)
146
- msgs[0].copy_out_string.should == @req.identity
147
- msgs[1].copy_out_string.should == "hello"
148
-
149
- @rep.send_strings(rep_data)
150
- msgs = []
151
- rc = @req.recvmsgs(msgs)
152
- msgs[0].copy_out_string.should == rep_data.last
153
- end
154
-
155
- end
156
-
157
- end # if version...
158
-
159
-
160
106
  end
161
107
  end
162
108
  end
@@ -5,32 +5,26 @@ module ZMQ
5
5
 
6
6
 
7
7
  describe Socket do
8
- before(:all) do
9
- @ctx = Context.new
10
- end
11
-
12
- after(:all) do
13
- @ctx.terminate
14
- end
8
+ include APIHelper
15
9
 
16
10
 
17
11
  shared_examples_for "any socket" do
18
12
 
19
13
  it "returns -1 when there are no messages to read" do
20
14
  array = []
21
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
15
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
22
16
  Util.resultcode_ok?(rc).should be_false
23
17
  end
24
18
 
25
19
  it "gets EAGAIN when there are no messages to read" do
26
20
  array = []
27
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
21
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
28
22
  ZMQ::Util.errno.should == ZMQ::EAGAIN
29
23
  end
30
24
 
31
25
  it "returns the given array unmodified when there are no messages to read" do
32
26
  array = []
33
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
27
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
34
28
  array.size.should be_zero
35
29
  end
36
30
 
@@ -39,24 +33,26 @@ module ZMQ
39
33
  shared_examples_for "sockets without exposed envelopes" do
40
34
 
41
35
  it "read the single message and returns a successful result code" do
42
- rc = @sender.send_string('test')
43
- Util.resultcode_ok?(rc).should be_true
44
- sleep 0.1 # give it time to deliver to the receiver
45
-
36
+ poll_it_for_read(@receiver) do
37
+ rc = @sender.send_string('test')
38
+ Util.resultcode_ok?(rc).should be_true
39
+ end
40
+
46
41
  array = []
47
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
42
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
48
43
  Util.resultcode_ok?(rc).should be_true
49
44
  array.size.should == 1
50
45
  end
51
46
 
52
47
  it "read all message parts transmitted and returns a successful result code" do
53
- strings = Array.new(10, 'test')
54
- rc = @sender.send_strings(strings)
55
- Util.resultcode_ok?(rc).should be_true
56
- sleep 0.1 # give it time to deliver to the sub socket
48
+ poll_it_for_read(@receiver) do
49
+ strings = Array.new(10, 'test')
50
+ rc = @sender.send_strings(strings)
51
+ Util.resultcode_ok?(rc).should be_true
52
+ end
57
53
 
58
54
  array = []
59
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
55
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
60
56
  Util.resultcode_ok?(rc).should be_true
61
57
  array.size.should == 10
62
58
  end
@@ -66,24 +62,26 @@ module ZMQ
66
62
  shared_examples_for "sockets with exposed envelopes" do
67
63
 
68
64
  it "read the single message and returns a successful result code" do
69
- rc = @sender.send_string('test')
70
- Util.resultcode_ok?(rc).should be_true
71
- sleep 0.1 # give it time to deliver to the receiver
65
+ poll_it_for_read(@receiver) do
66
+ rc = @sender.send_string('test')
67
+ Util.resultcode_ok?(rc).should be_true
68
+ end
72
69
 
73
70
  array = []
74
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
71
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
75
72
  Util.resultcode_ok?(rc).should be_true
76
73
  array.size.should == 1 + 1 # extra 1 for envelope
77
74
  end
78
75
 
79
76
  it "read all message parts transmitted and returns a successful result code" do
80
- strings = Array.new(10, 'test')
81
- rc = @sender.send_strings(strings)
82
- Util.resultcode_ok?(rc).should be_true
83
- sleep 0.1 # give it time to deliver to the sub socket
77
+ poll_it_for_read(@receiver) do
78
+ strings = Array.new(10, 'test')
79
+ rc = @sender.send_strings(strings)
80
+ Util.resultcode_ok?(rc).should be_true
81
+ end
84
82
 
85
83
  array = []
86
- rc = @receiver.recvmsgs(array, NonBlockingFlag)
84
+ rc = @receiver.recvmsgs(array, ZMQ::NonBlocking)
87
85
  Util.resultcode_ok?(rc).should be_true
88
86
  array.size.should == 10 + 1 # add 1 for the envelope
89
87
  end
@@ -96,21 +94,25 @@ module ZMQ
96
94
  include APIHelper
97
95
 
98
96
  before(:each) do
99
- @receiver = @ctx.socket ZMQ::SUB
100
- port = bind_to_random_tcp_port(@receiver)
97
+ @context = Context.new
98
+ poller_setup
99
+
100
+ endpoint = "inproc://nonblocking_test"
101
+ @receiver = @context.socket ZMQ::SUB
101
102
  assert_ok(@receiver.setsockopt(ZMQ::SUBSCRIBE, ''))
102
- @sender = @ctx.socket ZMQ::PUB
103
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
104
- sleep 0.3
103
+ @sender = @context.socket ZMQ::PUB
104
+ @receiver.bind(endpoint)
105
+ connect_to_inproc(@sender, endpoint)
105
106
  end
106
107
 
107
108
  after(:each) do
108
109
  @receiver.close
109
110
  @sender.close
111
+ @context.terminate
110
112
  end
111
113
 
112
114
  it_behaves_like "any socket"
113
- it_behaves_like "sockets without exposed envelopes"
115
+ #it_behaves_like "sockets without exposed envelopes" # see Jira LIBZMQ-270; fails with tcp transport
114
116
 
115
117
  end # describe 'non-blocking recvmsgs'
116
118
 
@@ -118,21 +120,26 @@ module ZMQ
118
120
  include APIHelper
119
121
 
120
122
  before(:each) do
121
- @receiver = @ctx.socket ZMQ::SUB
123
+ @context = Context.new
124
+ poller_setup
125
+
126
+ endpoint = "inproc://nonblocking_test"
127
+ @receiver = @context.socket ZMQ::SUB
122
128
  port = connect_to_random_tcp_port(@receiver)
123
129
  assert_ok(@receiver.setsockopt(ZMQ::SUBSCRIBE, ''))
124
- @sender = @ctx.socket ZMQ::PUB
125
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
126
- sleep 0.3
130
+ @sender = @context.socket ZMQ::PUB
131
+ @sender.bind(endpoint)
132
+ connect_to_inproc(@receiver, endpoint)
127
133
  end
128
134
 
129
135
  after(:each) do
130
136
  @receiver.close
131
137
  @sender.close
138
+ @context.terminate
132
139
  end
133
140
 
134
141
  it_behaves_like "any socket"
135
- it_behaves_like "sockets without exposed envelopes"
142
+ it_behaves_like "sockets without exposed envelopes" # see Jira LIBZMQ-270; fails with tcp transport
136
143
 
137
144
  end # describe 'non-blocking recvmsgs'
138
145
 
@@ -144,16 +151,20 @@ module ZMQ
144
151
  include APIHelper
145
152
 
146
153
  before(:each) do
147
- @receiver = @ctx.socket ZMQ::REP
148
- port = bind_to_random_tcp_port(@receiver)
149
- @sender = @ctx.socket ZMQ::REQ
150
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
151
- sleep 0.1
154
+ @context = Context.new
155
+ poller_setup
156
+
157
+ endpoint = "inproc://nonblocking_test"
158
+ @receiver = @context.socket ZMQ::REP
159
+ @sender = @context.socket ZMQ::REQ
160
+ @receiver.bind(endpoint)
161
+ connect_to_inproc(@sender, endpoint)
152
162
  end
153
163
 
154
164
  after(:each) do
155
165
  @receiver.close
156
166
  @sender.close
167
+ @context.terminate
157
168
  end
158
169
 
159
170
  it_behaves_like "any socket"
@@ -165,16 +176,20 @@ module ZMQ
165
176
  include APIHelper
166
177
 
167
178
  before(:each) do
168
- @receiver = @ctx.socket ZMQ::REP
169
- port = connect_to_random_tcp_port(@receiver)
170
- @sender = @ctx.socket ZMQ::REQ
171
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
172
- sleep 0.1
179
+ @context = Context.new
180
+ poller_setup
181
+
182
+ endpoint = "inproc://nonblocking_test"
183
+ @receiver = @context.socket ZMQ::REP
184
+ @sender = @context.socket ZMQ::REQ
185
+ @sender.bind(endpoint)
186
+ connect_to_inproc(@receiver, endpoint)
173
187
  end
174
188
 
175
189
  after(:each) do
176
190
  @receiver.close
177
191
  @sender.close
192
+ @context.terminate
178
193
  end
179
194
 
180
195
  it_behaves_like "any socket"
@@ -191,16 +206,20 @@ module ZMQ
191
206
  include APIHelper
192
207
 
193
208
  before(:each) do
194
- @receiver = @ctx.socket ZMQ::PULL
195
- port = bind_to_random_tcp_port(@receiver)
196
- @sender = @ctx.socket ZMQ::PUSH
197
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
198
- sleep 0.1
209
+ @context = Context.new
210
+ poller_setup
211
+
212
+ endpoint = "inproc://nonblocking_test"
213
+ @receiver = @context.socket ZMQ::PULL
214
+ @sender = @context.socket ZMQ::PUSH
215
+ @receiver.bind(endpoint)
216
+ connect_to_inproc(@sender, endpoint)
199
217
  end
200
218
 
201
219
  after(:each) do
202
220
  @receiver.close
203
221
  @sender.close
222
+ @context.terminate
204
223
  end
205
224
 
206
225
  it_behaves_like "any socket"
@@ -212,16 +231,20 @@ module ZMQ
212
231
  include APIHelper
213
232
 
214
233
  before(:each) do
215
- @receiver = @ctx.socket ZMQ::PULL
216
- port = connect_to_random_tcp_port(@receiver)
217
- @sender = @ctx.socket ZMQ::PUSH
218
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
219
- sleep 0.1
234
+ @context = Context.new
235
+ poller_setup
236
+
237
+ endpoint = "inproc://nonblocking_test"
238
+ @receiver = @context.socket ZMQ::PULL
239
+ @sender = @context.socket ZMQ::PUSH
240
+ @sender.bind(endpoint)
241
+ connect_to_inproc(@receiver, endpoint)
220
242
  end
221
243
 
222
244
  after(:each) do
223
245
  @receiver.close
224
246
  @sender.close
247
+ @context.terminate
225
248
  end
226
249
 
227
250
  it_behaves_like "any socket"
@@ -238,16 +261,20 @@ module ZMQ
238
261
  include APIHelper
239
262
 
240
263
  before(:each) do
241
- @receiver = @ctx.socket ZMQ::ROUTER
242
- port = bind_to_random_tcp_port(@receiver)
243
- @sender = @ctx.socket ZMQ::DEALER
244
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
245
- sleep 0.1
264
+ @context = Context.new
265
+ poller_setup
266
+
267
+ endpoint = "inproc://nonblocking_test"
268
+ @receiver = @context.socket ZMQ::ROUTER
269
+ @sender = @context.socket ZMQ::DEALER
270
+ @receiver.bind(endpoint)
271
+ connect_to_inproc(@sender, endpoint)
246
272
  end
247
273
 
248
274
  after(:each) do
249
275
  @receiver.close
250
276
  @sender.close
277
+ @context.terminate
251
278
  end
252
279
 
253
280
  it_behaves_like "any socket"
@@ -259,16 +286,20 @@ module ZMQ
259
286
  include APIHelper
260
287
 
261
288
  before(:each) do
262
- @receiver = @ctx.socket ZMQ::ROUTER
263
- port = connect_to_random_tcp_port(@receiver)
264
- @sender = @ctx.socket ZMQ::DEALER
265
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
266
- sleep 0.1
289
+ @context = Context.new
290
+ poller_setup
291
+
292
+ endpoint = "inproc://nonblocking_test"
293
+ @receiver = @context.socket ZMQ::ROUTER
294
+ @sender = @context.socket ZMQ::DEALER
295
+ @sender.bind(endpoint)
296
+ connect_to_inproc(@receiver, endpoint)
267
297
  end
268
298
 
269
299
  after(:each) do
270
300
  @receiver.close
271
301
  @sender.close
302
+ @context.terminate
272
303
  end
273
304
 
274
305
  it_behaves_like "any socket"
@@ -285,16 +316,20 @@ module ZMQ
285
316
  include APIHelper
286
317
 
287
318
  before(:each) do
288
- @receiver = @ctx.socket ZMQ::XREP
289
- port = bind_to_random_tcp_port(@receiver)
290
- @sender = @ctx.socket ZMQ::XREQ
291
- assert_ok(@sender.connect("tcp://127.0.0.1:#{port}"))
292
- sleep 0.1
319
+ @context = Context.new
320
+ poller_setup
321
+
322
+ endpoint = "inproc://nonblocking_test"
323
+ @receiver = @context.socket ZMQ::XREP
324
+ @sender = @context.socket ZMQ::XREQ
325
+ @receiver.bind(endpoint)
326
+ connect_to_inproc(@sender, endpoint)
293
327
  end
294
328
 
295
329
  after(:each) do
296
330
  @receiver.close
297
331
  @sender.close
332
+ @context.terminate
298
333
  end
299
334
 
300
335
  it_behaves_like "any socket"
@@ -306,16 +341,20 @@ module ZMQ
306
341
  include APIHelper
307
342
 
308
343
  before(:each) do
309
- @receiver = @ctx.socket ZMQ::XREP
310
- port = connect_to_random_tcp_port(@receiver)
311
- @sender = @ctx.socket ZMQ::XREQ
312
- assert_ok(@sender.bind("tcp://127.0.0.1:#{port}"))
313
- sleep 0.1
344
+ @context = Context.new
345
+ poller_setup
346
+
347
+ endpoint = "inproc://nonblocking_test"
348
+ @receiver = @context.socket ZMQ::XREP
349
+ @sender = @context.socket ZMQ::XREQ
350
+ @sender.bind(endpoint)
351
+ connect_to_inproc(@receiver, endpoint)
314
352
  end
315
353
 
316
354
  after(:each) do
317
355
  @receiver.close
318
356
  @sender.close
357
+ @context.terminate
319
358
  end
320
359
 
321
360
  it_behaves_like "any socket"