File: connection_stop_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 (83 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (5)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "spec_helper"

describe Bunny::Session do
  let(:http_client) { RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }

  def close_connection(client_port)
    # let whatever actions were taken before
    # this call a chance to propagate, e.g. to make
    # sure that connections are accounted for in the
    # stats DB.
    #
    # See bin/ci/before_build for management plugin
    # pre-configuration.
    #
    # MK.
    sleep 1.1
    c = http_client.
      list_connections.
      find   { |conn_info| conn_info && conn_info.peer_port.to_i == client_port }

    http_client.close_connection(c.name) if c
  end

  def wait_for_recovery
    sleep 1.5
  end

  it "can be closed" do
    c  = Bunny.new(automatically_recover: false)
    c.start
    ch = c.create_channel

    expect(c).to be_connected
    c.stop
    expect(c).to be_closed
  end

  it "can be closed twice (Session#close is idempotent)" do
    c  = Bunny.new(automatically_recover: false)
    c.start
    ch = c.create_channel

    expect(c).to be_connected
    c.stop
    expect(c).to be_closed
    c.stop
    expect(c).to be_closed
  end

  describe "in a single threaded mode" do
    it "can be closed" do
      c  = Bunny.new(automatically_recover: false, threaded: false)
      c.start
      ch = c.create_channel

      expect(c).to be_connected
      c.stop
      expect(c).to be_closed
    end
  end


  describe "that recovers from connection.close" do
    it "can be closed" do
      c  = Bunny.new(automatically_recover: true,
        recover_from_connection_close: true,
        network_recovery_interval: 0.2)
      c.start
      ch = c.create_channel

      sleep 1.5
      expect(c).to be_open
      sleep 1.5
      close_connection(c.local_port)

      wait_for_recovery
      expect(c).to be_open
      expect(ch).to be_open

      c.close
    end
  end
end