/
ticker_spec.rb
60 lines (50 loc) · 1.43 KB
/
ticker_spec.rb
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
58
59
60
require_relative 'timing_buffer_shared'
module Concurrent::Channel::Buffer
RSpec.describe Ticker, edge: true do
let(:delay) { 0.1 }
subject { described_class.new(delay) }
it_behaves_like :channel_timing_buffer
context '#take' do
it 'triggers until closed' do
expected = 3
actual = 0
expected.times { actual += 1 if subject.take.is_a? Concurrent::Channel::Tick }
expect(actual).to eq expected
end
it 'returns Concurrent::NULL when closed after trigger' do
subject.take
subject.close
expect(subject).to be_closed
expect(subject.take).to eq Concurrent::NULL
end
end
context '#poll' do
it 'triggers until closed' do
expected = 3
actual = 0
expected.times do
until subject.poll.is_a?(Concurrent::Channel::Tick)
actual += 1
end
end
end
end
context '#next' do
it 'triggers until closed' do
expected = 3
actual = 0
expected.times { actual += 1 if subject.next.first.is_a? Concurrent::Channel::Tick }
expect(actual).to eq expected
end
it 'returns true for more while open' do
_, more = subject.next
expect(more).to be true
end
it 'returns false for more once closed' do
subject.close
_, more = subject.next
expect(more).to be false
end
end
end
end