File: dropping_spec.rb

package info (click to toggle)
ruby-concurrent 1.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,152 kB
  • sloc: ruby: 30,953; java: 6,128; ansic: 293; makefile: 26; sh: 19
file content (49 lines) | stat: -rw-r--r-- 1,288 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
require_relative 'buffered_shared'
require 'concurrent/channel/buffer/dropping'

module Concurrent::Channel::Buffer

  RSpec.describe Dropping, edge: true do

    subject { described_class.new(10) }

    it_behaves_like :channel_buffered_buffer

    specify do
      expect(subject).to_not be_blocking
    end

    context '#put' do

      it 'does not block when full' do
        subject = described_class.new(1)
        3.times {|i| expect(subject.put(i)).to be true }
      end

      it 'drops the last value when full' do
        subject = described_class.new(1)
        3.times{|i| subject.put(i)}
        internal_buffer = subject.instance_variable_get(:@buffer)
        expect(internal_buffer.size).to eq 1
        expect(internal_buffer.first).to eq 0
      end
    end

    context '#offer' do

      it 'returns true immediately when full' do
        subject = described_class.new(1)
        subject.put(:foo)
        expect(subject.offer(:bar)).to be true
      end

      it 'drops the last value when full' do
        subject = described_class.new(1)
        3.times{|i| subject.offer(i)}
        internal_buffer = subject.instance_variable_get(:@buffer)
        expect(internal_buffer.size).to eq 1
        expect(internal_buffer.first).to eq 0
      end
    end
  end
end