File: ticker_spec.rb

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; javascript: 1,114; ansic: 288; makefile: 10; sh: 6
file content (60 lines) | stat: -rw-r--r-- 1,477 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
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, notravis: 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