From 2be410c668f1829c3910975d71c4afb470b9e1cf Mon Sep 17 00:00:00 2001 From: Dawid Sklodowski Date: Mon, 22 Sep 2014 15:17:21 +0100 Subject: [PATCH] Additional specs --- spec/moped/cluster_spec.rb | 47 +++++++++++++++++++++++++++++++ spec/moped/node_spec.rb | 20 +++++++------ spec/moped/operation/read_spec.rb | 2 +- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/spec/moped/cluster_spec.rb b/spec/moped/cluster_spec.rb index f51111c..18bf54e 100644 --- a/spec/moped/cluster_spec.rb +++ b/spec/moped/cluster_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/moped/node_spec.rb b/spec/moped/node_spec.rb index 9853cef..c1b4217 100644 --- a/spec/moped/node_spec.rb +++ b/spec/moped/node_spec.rb @@ -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 @@ -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 diff --git a/spec/moped/operation/read_spec.rb b/spec/moped/operation/read_spec.rb index 3bb5300..44cf274 100644 --- a/spec/moped/operation/read_spec.rb +++ b/spec/moped/operation/read_spec.rb @@ -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