Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Mark node as not down when alive connection was acquired #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/moped/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def ensure_connected(&block)

begin
connection do |conn|
connect(conn) unless conn.alive?
if conn.alive?
@down_at = nil
else
connect(conn)
end
conn.apply_credentials(@credentials)
stack(:connection) << conn
yield(conn)
Expand Down
15 changes: 15 additions & 0 deletions spec/moped/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,21 @@
end
end
end

context 'when node was down' do
before { node.down! }

context 'and good connection popped out of the pool' do
before { allow_any_instance_of(Moped::Connection).to receive(:alive?).and_return true }

it 'marks node as not down' do
node.ensure_connected do
node.command("admin", ping: 1)
end
expect(node).not_to be_down
end
end
end
end

describe "#initialize" do
Expand Down