File: issue656_spec.rb

package info (click to toggle)
ruby-bunny 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 10,256; sh: 70; makefile: 8
file content (61 lines) | stat: -rw-r--r-- 1,697 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
require 'spec_helper'

describe Bunny::Session do
  context 'when created' do
    let(:io) { StringIO.new } # keep test output clear

    def create_session
      described_class.new(
        host: 'fake.host',
        recovery_attempts: 0,
        connection_timeout: 0,
        network_recovery_interval: 0,
        logfile: io,
        )
    end

    it 'has default exceptions' do
      session = create_session
      expect(session.recoverable_exceptions).to eq(Bunny::Session::DEFAULT_RECOVERABLE_EXCEPTIONS)
    end

    it 'can override exceptions' do
      session = create_session
      session.recoverable_exceptions = [StandardError]
      expect(session.recoverable_exceptions).to eq([StandardError])
    end

    it 'can append exceptions' do
      session = create_session
      session.recoverable_exceptions << StandardError
      expect(session.recoverable_exceptions).to eq(Bunny::Session::DEFAULT_RECOVERABLE_EXCEPTIONS.append(StandardError))
    end
  end

  context 'when retry attempts have been exhausted' do
    let(:io) { StringIO.new } # keep test output clear

    def create_session
      described_class.new(
        host: 'fake.host',
        recovery_attempts: 0,
        connection_timeout: 0,
        network_recovery_interval: 0,
        logfile: io,
      )
    end

    it 'closes the session' do
      session = create_session
      session.handle_network_failure(StandardError.new)
      expect(session.closed?).to be true
    end

    it 'stops the reader loop' do
      session = create_session
      reader_loop = session.reader_loop
      session.handle_network_failure(StandardError.new)
      expect(reader_loop.stopping?).to be true
    end
  end
end