You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/03/20 13:44:23 UTC
qpid-proton git commit: PROTON-1791: [ruby] Fix test race condition
Repository: qpid-proton
Updated Branches:
refs/heads/master 95776152d -> c82de9d3d
PROTON-1791: [ruby] Fix test race condition
Fix race in ruby tests causing this error:
NoMethodError: undefined method `virtual_host' for nil:NilClass
/home/travis/build/apache/qpid-proton/proton-c/bindings/ruby/tests/test_container.rb:189:in
`test_connection_options'
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/c82de9d3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/c82de9d3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/c82de9d3
Branch: refs/heads/master
Commit: c82de9d3d221ff7d30d5669b0a8f3763ccd85b7b
Parents: 9577615
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Mar 20 09:33:05 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Mar 20 09:33:05 2018 -0400
----------------------------------------------------------------------
proton-c/bindings/ruby/tests/test_container.rb | 13 +++++++++++--
proton-c/bindings/ruby/tests/test_tools.rb | 15 ++++-----------
2 files changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c82de9d3/proton-c/bindings/ruby/tests/test_container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_container.rb b/proton-c/bindings/ruby/tests/test_container.rb
index bed810c..29cf985 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -31,6 +31,9 @@ class ContainerTest < MiniTest::Test
def test_simple()
send_handler = Class.new(ExceptionMessagingHandler) do
attr_reader :accepted, :sent
+
+ def initialize() @ready = Queue.new; end
+
def on_sendable(sender)
sender.send Message.new("foo") unless @sent
@sent = true
@@ -39,7 +42,10 @@ class ContainerTest < MiniTest::Test
def on_tracker_accept(tracker)
@accepted = true
tracker.connection.close
+ @ready << nil
end
+
+ def wait() @ready.pop(); end
end.new
receive_handler = Class.new(ExceptionMessagingHandler) do
@@ -59,6 +65,7 @@ class ContainerTest < MiniTest::Test
c = ServerContainer.new(__method__, {:handler => receive_handler})
c.connect(c.url, {:handler => send_handler}).open_sender({:name => "testlink"})
+ send_handler.wait
c.wait
assert send_handler.accepted
@@ -153,8 +160,9 @@ class ContainerTest < MiniTest::Test
def test_connection_options
# Note: user, password and sasl_xxx options are tested by ContainerSASLTest below
server_handler = Class.new(ExceptionMessagingHandler) do
+ def initialize() @connection = Queue.new; end
def on_connection_open(c)
- @connection = c
+ @connection << c
c.open({
:virtual_host => "server.to.client",
:properties => { :server => :client },
@@ -183,9 +191,10 @@ class ContainerTest < MiniTest::Test
:max_frame_size => 4096,
:container_id => "bowl"
})
+ server = server_handler.connection.pop
cont.wait
- c = server_handler.connection
+ c = server
assert_equal "client.to.server", c.virtual_host
assert_equal({ :foo => :bar, :str => "str" }, c.properties)
assert_equal([:c1], c.offered_capabilities)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c82de9d3/proton-c/bindings/ruby/tests/test_tools.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_tools.rb b/proton-c/bindings/ruby/tests/test_tools.rb
index 37e757c..5b88ca9 100644
--- a/proton-c/bindings/ruby/tests/test_tools.rb
+++ b/proton-c/bindings/ruby/tests/test_tools.rb
@@ -150,26 +150,19 @@ end
class ServerContainer < Qpid::Proton::Container
include Qpid::Proton
- class ListenerHandler < Listener::Handler
- def initialize(opts) super; @ready = Queue.new; end
- def on_open(l) @ready.push nil; end
- def wait() @ready.pop; end
- end
-
def initialize(id=nil, listener_opts=nil)
super id
- lh = ListenerHandler.new(listener_opts)
- @listener = listen_io(TCPServer.open(0), lh)
+ @listener = listen_io(TCPServer.open(0), Listener::Handler.new(listener_opts))
@thread = Thread.new { run }
- # Wait for listener to avoid nasty race conditions where a test closes the
- # listener before it opens and therefore nothing happens.
- lh.wait
end
attr_reader :listener
def port() @listener.port; end
def url() "amqp://:#{port}"; end
+
+ # NOTE: the test must have already waited for some events to happen before
+ # calling this, otherwise the listener can close before it opens and nothing happens
def wait() @listener.close; @thread.join; end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org