test/test_socket.rb in rbczmq-1.7.4 vs test/test_socket.rb in rbczmq-1.7.5
- old
+ new
@@ -1,8 +1,8 @@
# encoding: utf-8
-require File.join(File.dirname(__FILE__), 'helper')
+require File.expand_path("../helper.rb", __FILE__)
class TestZmqSocket < ZmqTestCase
def test_recv_timeout
ctx = ZMQ::Context.new
rep = ctx.bind(:REP, "inproc://test.socket-recv-timeout")
@@ -181,17 +181,17 @@
port = rep.bind("tcp://127.0.0.1:*")
req = ctx.socket(:REQ)
assert(req.state & ZMQ::Socket::PENDING)
req.connect("tcp://127.0.0.1:#{port}")
assert_equal "PAIR socket", sock.to_s
- assert_equal "REP socket bound to tcp://127.0.0.1:*", rep.to_s
+ assert_equal "REP socket bound to tcp://127.0.0.1:#{port}", rep.to_s
assert_equal "REQ socket connected to tcp://127.0.0.1:#{port}", req.to_s
port2 = rep.bind("tcp://127.0.0.1:*")
req.connect("tcp://127.0.0.1:#{port2}")
- assert_equal "REP socket bound to tcp://127.0.0.1:*, tcp://127.0.0.1:*", rep.to_s
+ assert_equal "REP socket bound to tcp://127.0.0.1:#{port}, tcp://127.0.0.1:#{port2}", rep.to_s
assert_equal "REQ socket connected to tcp://127.0.0.1:#{port}, tcp://127.0.0.1:#{port2}", req.to_s
ensure
ctx.destroy
end
@@ -199,11 +199,11 @@
ctx = ZMQ::Context.new
rep = ctx.socket(:REP)
port = rep.bind("tcp://127.0.0.1:*")
req = ctx.socket(:REQ)
req.connect("tcp://127.0.0.1:#{port}")
- assert_equal "tcp://127.0.0.1:*", rep.endpoint
+ assert_equal "tcp://127.0.0.1:#{port}", rep.endpoint
assert_equal "tcp://127.0.0.1:#{port}", req.endpoint
ensure
ctx.destroy
end
@@ -211,16 +211,16 @@
ctx = ZMQ::Context.new
rep = ctx.socket(:REP)
port = rep.bind("tcp://127.0.0.1:*")
req = ctx.socket(:REQ)
req.connect("tcp://127.0.0.1:#{port}")
- assert_equal ["tcp://127.0.0.1:*"], rep.endpoints
+ assert_equal ["tcp://127.0.0.1:#{port}"], rep.endpoints
assert_equal ["tcp://127.0.0.1:#{port}"], req.endpoints
port2 = rep.bind("tcp://127.0.0.1:*")
req.connect("tcp://127.0.0.1:#{port2}")
- assert_equal ["tcp://127.0.0.1:*", "tcp://127.0.0.1:*"], rep.endpoints
+ assert_equal ["tcp://127.0.0.1:#{port}", "tcp://127.0.0.1:#{port2}"], rep.endpoints
assert_equal ["tcp://127.0.0.1:#{port}", "tcp://127.0.0.1:#{port2}"], req.endpoints
ensure
ctx.destroy
end
@@ -556,6 +556,53 @@
sub_sock.subscribe("ruby")
sub_sock.unsubscribe("ruby")
ensure
ctx.destroy
end
+
+ def test_last_endpoint
+ ctx = ZMQ::Context.new
+ sock = ctx.socket(ZMQ::PULL)
+ port = sock.bind('tcp://127.0.0.1:*')
+ assert_equal sock.last_endpoint, "tcp://127.0.0.1:#{port}"
+ ensure
+ ctx.destroy
+ end
+
+ def test_ephemeral_bind
+ ctx = ZMQ::Context.new
+ sock = ctx.socket(ZMQ::PULL)
+ port = sock.bind('tcp://127.0.0.1:*')
+ assert sock.endpoints.include?("tcp://127.0.0.1:#{port}")
+ ensure
+ ctx.destroy
+ end
+
+ def test_ephemral_bind_and_unbind
+ ctx = ZMQ::Context.new
+ sock = ctx.socket(ZMQ::PULL)
+ port = sock.bind('tcp://127.0.0.1:*')
+ sock.unbind("tcp://127.0.0.1:#{port}")
+ assert sock.endpoints.count == 0
+ ensure
+ ctx.destroy
+ end
+
+ def test_pollable_after_bind_and_unbind
+ ctx = ZMQ::Context.new
+ router = ctx.socket(ZMQ::ROUTER)
+ port1 = router.bind('tcp://127.0.0.1:*')
+ dealer = ctx.socket(ZMQ::DEALER)
+ dealer.connect(router.last_endpoint)
+ port2 = router.bind('tcp://127.0.0.1:*')
+ dealer.send("hello")
+ sleep(0.01)
+ assert_equal router.poll(0), true
+ router.unbind("tcp://127.0.0.1:#{port2}")
+ assert_equal router.poll(0), true
+ message = router.recv_message
+ assert_equal message.last.to_s, "hello"
+ ensure
+ ctx.destroy
+ end
+
end