Sha256: 7d1fa259a72e17fc3e7d3948919614270fe52fc7462ce02caca0968e997ef544

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dalli-2.6.3 test/test_network.rb
dalli-2.6.2 test/test_network.rb
dalli-2.6.1 test/test_network.rb
dalli-2.6.0 test/test_network.rb
dalli-2.5.0 test/test_network.rb
dalli-2.3.0 test/test_network.rb
dalli-2.2.1 test/test_network.rb
dalli-2.2.0 test/test_network.rb
dalli-2.1.0 test/test_network.rb
dalli-2.0.5 test/test_network.rb
dalli-2.0.4 test/test_network.rb
dalli-2.0.3 test/test_network.rb
dalli-2.0.2 test/test_network.rb
dalli-2.0.1 test/test_network.rb
dalli-2.0.0 test/test_network.rb
dalli-1.1.5 test/test_network.rb