Sha256: a3485f31894b768e17cc79f23db85771223da07f40573c0c64d9891e176c85d9

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

require "spec_helper"
require "em-synchrony/redis-sentinel"
require "eventmachine"

describe Redis::Client do
  context "#auto_retry_with_timeout" do
    subject { described_class.new(:failover_reconnect_timeout => 3,
                                :failover_reconnect_wait => 0.1) }
    context "configured wait time" do

      it "uses the wait time and blocks em" do
        allow(Time).to receive(:now).and_return(100, 101, 105)
        flag = false; EM.next_tick { flag = true }
        expect(subject).to receive(:sleep).with(0.1).and_return(0.1)
        begin
          subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
        rescue Redis::CannotConnectError
        end
        expect(flag).to be_false
      end

      it "uses the wait time and doesn't block em" do
        allow(Time).to receive(:now).and_return(100, 101, 105)
        flag = false; EM.next_tick { flag = true }
        begin
          subject.auto_retry_with_timeout { raise Redis::CannotConnectError }
        rescue Redis::CannotConnectError
        end
        expect(flag).to be_true
      end
    end
  end

  around(:each) do |testcase|
    EM.run do
      Fiber.new do
        begin
          testcase.call
        ensure
          EM.stop
        end
      end.resume
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redis-sentinel-1.4.4 spec/redis-sentinel/em_client_spec.rb
redis-sentinel-1.4.3 spec/redis-sentinel/em_client_spec.rb
redis-sentinel-1.4.2 spec/redis-sentinel/em_client_spec.rb
redis-sentinel-1.4.1 spec/redis-sentinel/em_client_spec.rb
redis-sentinel-1.4.0 spec/redis-sentinel/em_client_spec.rb