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

Fix + spec for #345. #353

Merged
merged 3 commits into from
Feb 12, 2015
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Overview

## Next

### Resolved Issues

* \#345
Writes fail with ConnectionPool::PoolShuttingDownError. (fedenusy, dblock)

## 2.0.3

### Resolved Issues
Expand Down
4 changes: 2 additions & 2 deletions lib/moped/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def disconnect
#
# @since 2.0.0
def down!
@pool = Connection::Manager.shutdown(self)
@down_at = Time.new
@pool = nil
@latency = nil
true
Connection::Manager.shutdown(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should still return true here , and not nil.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring says # @return [ nil ] Nothing., so we should update that as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point... if doc says that, I think it is fine to return nil

end

# Yields the block if a connection can be established, retrying when a
Expand Down
32 changes: 25 additions & 7 deletions spec/moped/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,33 @@
end
end

pending '#down!' do
describe '#down!' do
describe 'when connected' do
before do
node.connected?
end

before do
node.connected?
node.down!
end
describe 'shutdown' do
before do
node.down!
end

it 'clears out the connection pool' do
expect(node.instance_variable_get(:@pool)).to be_nil
it 'clears out the connection pool' do
expect(node.instance_variable_get(:@pool)).to be_nil
end
end

describe 'shutdown from multiple threads' do
before do
# fake the behavior of @pool that holds its value until shutdown returns
allow(Moped::Connection::Manager).to receive(:shutdown).and_return(node.instance_variable_get(:@pool)).once
node.down!
end

it 'clears out the connection pool before returning' do
expect(node.instance_variable_get(:@pool)).to be_nil
end
end
end
end

Expand Down