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_relative 'buffered_shared'
module Concurrent::Channel::Buffer
RSpec.describe Sliding, edge: true, notravis: 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 first 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 2
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 first 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 2
end
end
end
end
|