File: atomic_fixnum_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 (35 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (6)
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
require "spec_helper"
require "bunny/concurrent/atomic_fixnum"

describe Bunny::Concurrent::AtomicFixnum do
  it "allows retrieving the current value" do
    af = described_class.new(0)

    expect(af.get).to eq 0
    expect(af).to eq 0
  end

  it "can be updated" do
    af = described_class.new(0)

    expect(af.get).to eq 0
    Thread.new do
      af.set(10)
    end
    sleep 0.6
    expect(af.get).to eq 10
  end

  it "can be incremented" do
    af = described_class.new(0)

    expect(af.get).to eq 0
    10.times do
      Thread.new do
        af.increment
      end
    end
    sleep 0.6
    expect(af.get).to eq 10
  end
end