Sha256: ac38733651d5864321a5bc7b3d360cb13fa9836a1eef1413cbb351ff35dd8666

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require 'spec/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{}
    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{}
    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{ 1 }
    simulate_timeout
    cache.get('x').should == 1
    cache.read_error_occurred.should == true
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cachy-0.2.1 spec/cachy/memcache_timeout_protection_spec.rb
cachy-0.2.0 spec/cachy/memcache_timeout_protection_spec.rb
cachy-0.1.7 spec/cachy/memcache_timeout_protection_spec.rb
cachy-0.1.6 spec/cachy/memcache_timeout_protection_spec.rb