File: multi_message_ack_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 (48 lines) | stat: -rw-r--r-- 1,113 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
require "spec_helper"

unless ENV["CI"]
  describe "Subscription acknowledging multi-messages" do
    before :all do
      @connection = Bunny.new(username: "bunny_gem", password: "bunny_password",
        vhost: "bunny_testbed", automatically_recover: false)
      @connection.start
    end

    let(:max_messages) { 100_000 }

    it "successfully completes" do
      body = "."

      ch = @connection.create_channel
      ch.confirm_select

      q = ch.queue("multi-messages")

      m = Mutex.new
      acks = 0
      pubs = 0
      last = Bunny::Timestamp.now

      q.subscribe(manual_ack: true) do |delivery_info, _, _|
        sleep(0) if rand < 0.01
        ch.ack(delivery_info.delivery_tag)

        m.synchronize do
          acks += 1
          now = Bunny::Timestamp.now
          if now - last > 0.5
            puts "Ack multi-message: acks=#{acks} pubs=#{pubs}"
            last = now
          end
        end
      end

      (1..max_messages).each do
        q.publish(".")
        m.synchronize { pubs += 1 }
      end

      sleep 0.1 while m.synchronize { acks < pubs }
    end
  end
end