diff --git a/spec/client_reconnect_spec.rb b/spec/client_reconnect_spec.rb index df68eb4..7ddc9fd 100644 --- a/spec/client_reconnect_spec.rb +++ b/spec/client_reconnect_spec.rb @@ -620,27 +620,42 @@ end end - it "closes all its threads before reconnection" do - responder = NATS.connect - requester = NATS.connect( - reconnect: true, - reconnect_time_wait: 2, - max_reconnect_attempts: 1 - ) + describe "#process_op_error" do + # Close all dangling nats threads from previous tests + before do + Thread.list.each do |thread| + thread.exit if thread.name&.start_with?("nats:") + end + end - responder.subscribe("foo") { |msg| msg.respond("bar") } - requester.request("foo") + let(:responder) { NATS.connect } - nats_threads = Thread.list.select do |thread| - thread.name&.start_with?("nats:") + let(:requester) do + NATS.connect( + reconnect: true, + reconnect_time_wait: 2, + max_reconnect_attempts: 1 + ) end - @s.restart - sleep 2 + it "closes all its threads before reconnection" do + responder.subscribe("foo") { |msg| msg.respond("bar") } + requester.request("foo") + + nats_threads = Thread.list.select do |thread| + thread.name&.start_with?("nats:") + end - expect(Thread.list & nats_threads).to be_empty + @s.restart + sleep 2 - responder.close - requester.close + pp "RECONNECT" + pp "NATS: #{nats_threads.map{|t|[t.name, t.object_id]}}" + pp "Thread: #{Thread.list.map{|t|[t.name, t.object_id]}}" + expect(Thread.list & nats_threads).to be_empty + + responder.close + requester.close + end end end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index d2af3f5..3823f90 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -560,6 +560,13 @@ describe "#close" do context "when client has established a connection" do + before do + # Close all dangling nats threads from previous tests + Thread.list.each do |thread| + thread.exit if thread.name&.start_with?("nats:") + end + end + let(:responder) { NATS.connect(servers: [@s.uri]) } let(:requester) { NATS.connect(servers: [@s.uri]) } @@ -574,6 +581,9 @@ requester.close responder.close + pp "CLOSE" + pp "NATS: #{nats_threads.map{|t|[t.name, t.object_id]}}" + pp "Thread: #{Thread.list.map{|t|[t.name, t.object_id]}}" expect(Thread.list & nats_threads).to be_empty end end