File: basic_qos_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 (57 lines) | stat: -rw-r--r-- 1,626 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
require "spec_helper"

describe Bunny::Channel, "#prefetch" do
  let(:connection) do
    c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
    c.start
    c
  end

  after :each do
    connection.close
  end

  context "with a positive integer < 65535" do
    it "sets that prefetch level via basic.qos" do
      ch = connection.create_channel
      expect(ch.prefetch_count).not_to eq 10
      expect(ch.prefetch_global).to be_nil
      expect(ch.prefetch(10)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
      expect(ch.prefetch_count).to eq 10
      expect(ch.prefetch_global).to be false
    end

    it "sets that prefetch global via basic.qos" do
      ch = connection.create_channel
      expect(ch.prefetch_count).not_to eq 42
      expect(ch.prefetch_global).to be_nil
      expect(ch.prefetch(42, true)).to be_instance_of(AMQ::Protocol::Basic::QosOk)
      expect(ch.prefetch_count).to eq 42
      expect(ch.prefetch_global).to be true
    end
  end

  context "with a positive integer > 65535" do
    it "raises an ArgumentError" do
      ch = connection.create_channel
      expect {
        ch.prefetch(100_000)
      }.to raise_error(
        ArgumentError,
        "prefetch count must be no greater than #{Bunny::Channel::MAX_PREFETCH_COUNT}, given: 100000"
      )
    end
  end

  context "with a negative integer" do
    it "raises an ArgumentError" do
      ch = connection.create_channel
      expect {
        ch.prefetch(-2)
      }.to raise_error(
        ArgumentError,
        "prefetch count must be a positive integer, given: -2"
      )
    end
  end
end