Sha256: aa0b6d8cecf46b39bfd971ce535288ac3924c5326737a614a0f09e9d617d5c4f

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require "spec_helper"

describe Moped::Failover::Retry do

  describe "#execute" do

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

    let(:exception) do
      Moped::Errors::ConnectionFailure.new
    end

    context "when the retry succeeds" do

      it "returns the result of the yield" do
        expect(described_class.execute(exception, node) { "test" }).to eq("test")
      end
    end

    context "when the retry fails" do

      it "re-raises the exception" do
        expect {
          described_class.execute(exception, node) do
            raise(exception)
          end
        }.to raise_error(exception.class)
      end

      it "disconnects the node" do
        begin
          described_class.execute(exception, node) do
            raise(exception)
          end
        rescue Exception => e
          expect(node).to_not be_connected
        end
      end

      it "flags the node as down" do
        begin
          described_class.execute(exception, node) do
            raise(exception)
          end
        rescue Exception => e
          expect(node).to be_down
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/spec/moped/failover/retry_spec.rb