Sha256: bc49248ed870811cd0e2fa7d88adf4f49f11e2e72769134592021fe9ac7aec67

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'
require './spec/mem_cache'
require 'cachy/memcache_timeout_protection'

describe "MemCache timeout protection" do
  before do
    MemCache.read_error_callback = nil
  end

  let(:cache){ MemCache.new }

  def simulate_timeout
    cache.stub!(:stubable_cache_get).and_raise('IO timeout')
  end

  it "has no errors by default" do
    cache.read_error_occurred.should == nil
  end

  it "catches timeout errors" do
    MemCache.read_error_callback = lambda{|x|}
    simulate_timeout
    cache.get('x').should == nil
    cache.read_error_occurred.should == true
  end

  it "resets error_occurred to false after successful get" do
    MemCache.read_error_callback = lambda{|x|}
    simulate_timeout
    cache.get('x').should == nil
    cache.stub!(:stubable_cache_get).and_return 1
    cache.get('x').should == 1
    cache.read_error_occurred.should == false
  end

  it "raises if no callback is given" do
    simulate_timeout
    lambda{
      cache.get('x').should == nil
    }.should raise_error
    cache.read_error_occurred.should == true
  end

  it "calls the callback" do
    MemCache.read_error_callback = lambda{|x| 1 }
    simulate_timeout
    cache.get('x').should == 1
    cache.read_error_occurred.should == true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cachy-0.3.1 spec/cachy/memcache_timeout_protection_spec.rb
cachy-0.3.0 spec/cachy/memcache_timeout_protection_spec.rb