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

Commit

Permalink
Additional specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dawid-sklodowski committed Sep 22, 2014
1 parent 827bedc commit 2be410c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
47 changes: 47 additions & 0 deletions spec/moped/cluster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@
end.should raise_exception(Moped::Errors::ConnectionFailure)
end
end

describe '#with_retry' do
it 'retries' do
cluster.should_receive(:with_retry).twice.and_call_original
lambda do
cluster.with_retry do
cluster.with_secondary do |node|
node.command("admin", ping: 1)
end
end
end.should raise_exception(Moped::Errors::ConnectionFailure)
end

it 'raises connection error' do
lambda do
cluster.with_retry do
cluster.with_secondary do |node|
node.command("admin", ping: 1)
end
end
end.should raise_exception(Moped::Errors::ConnectionFailure)
end
end
end

context "when the replica set hasn't connected yet" do
Expand Down Expand Up @@ -95,6 +118,19 @@
end
end.should raise_exception(Moped::Errors::ConnectionFailure)
end

context 'with_retry' do
it 'raises connection error after retrying' do
cluster.should_receive(:with_retry).twice.and_call_original
lambda do
cluster.with_retry do
cluster.with_primary do |node|
node.command("admin", ping: 1)
end
end
end.should raise_exception(Moped::Errors::ConnectionFailure)
end
end
end

describe "#with_secondary" do
Expand All @@ -104,6 +140,17 @@
@secondaries.map(&:address).should include node.address.original
end
end

context 'with_retry' do
it 'does not retry' do
cluster.should_receive(:with_retry).once.and_call_original
cluster.with_retry do
cluster.with_secondary do |node|
node.command("admin", ping: 1)
end
end
end
end
end
end

Expand Down
20 changes: 12 additions & 8 deletions spec/moped/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,16 @@

describe "#refresh" do

context "when the ismaster command fails" do
let(:node) do
described_class.new("127.0.0.1:27017")
end

let(:node) do
described_class.new("127.0.0.1:27017")
end
it 'marks node as not down any more when it succeeds to refresh' do
node.down!
expect{ node.refresh }.to change{ node.down? }.to(nil)
end

context "when the ismaster command fails" do
before do
node.should_receive(:command).with("admin", ismaster: 1).and_raise(Timeout::Error)
node.refresh
Expand All @@ -383,14 +387,14 @@
it "still sets the refresh time" do
expect(node.refreshed_at).to_not be_nil
end

it 'keeps node down' do
expect(node).to be_down
end
end

context "when the node has authentication details" do

let(:node) do
described_class.new("127.0.0.1:27017")
end

before do
node.credentials["moped_test"] = [ "user", "pass" ]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/moped/operation/read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
replica_set_node.unauthorized_on_next_message!
end

it "does not raise a failure error (it retries and succeeds)" do
it "does not raise a failure error (as it retries and succeeds)" do
expect {
read.execute(node)
}.to_not raise_error
Expand Down

0 comments on commit 2be410c

Please sign in to comment.