File: timer_spec.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (46 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
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
class EveryActor
  include Celluloid

  def initialize
    @trace = []
    @times = []
    @start = Time.now

    every(1) { log(1) }
    every(2) { log(2) }
    every(1) { log(11) }
    every(2) { log(22) }
  end

  def log(t)
    @trace << t

    offset = Time.now - @start
    @times << offset

    # puts "log(#{t}) @ #{offset}"
  end

  attr_reader :trace
  attr_reader :times
end

RSpec.describe "Celluloid::Actor timers" do
  it "run every(t) task several times" do
    Celluloid.boot

    every_actor = EveryActor.new

    sleep 5.5

    every_actor.times
    trace = every_actor.trace

    Celluloid.shutdown

    expect(trace.count(1)).to be == 5
    expect(trace.count(11)).to be == 5
    expect(trace.count(2)).to be == 2
    expect(trace.count(22)).to be == 2
  end
end