Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (45 sloc) 1.571 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
require 'helper'

describe 'Network' do

  context 'assuming a bad network' do

    should 'handle no server available' do
      assert_raises Dalli::RingError, :message => "No server available" do
        dc = Dalli::Client.new 'localhost:19333'
        dc.get 'foo'
      end
    end

    context 'with a fake server' do
      should 'handle connection reset' do
        memcached_mock(lambda {|sock| sock.close }) do
          assert_raises Dalli::RingError, :message => "No server available" do
            dc = Dalli::Client.new('localhost:19123')
            dc.get('abc')
          end
        end
      end

      should 'handle malformed response' do
        memcached_mock(lambda {|sock| sock.write('123') }) do
          assert_raises Dalli::RingError, :message => "No server available" do
            dc = Dalli::Client.new('localhost:19123')
            dc.get('abc')
          end
        end
      end

      should 'handle connect timeouts' do
        memcached_mock(lambda {|sock| sleep(0.6); sock.close }, :delayed_start) do
          assert_raises Dalli::RingError, :message => "No server available" do
            dc = Dalli::Client.new('localhost:19123')
            dc.get('abc')
          end
        end
      end

      should 'handle read timeouts' do
        memcached_mock(lambda {|sock| sleep(0.6); sock.write('giraffe') }) do
          assert_raises Dalli::RingError, :message => "No server available" do
            dc = Dalli::Client.new('localhost:19123')
            dc.get('abc')
          end
        end
      end

    end

  end
end
Something went wrong with that request. Please try again.