Sha256: a172ba2842983356e20bc65ad3d5ab43c96ea31402bf622cc732b487873ab9c7

Contents?: true

Size: 1.45 KB

Versions: 45

Compression:

Stored size: 1.45 KB

Contents

require File.expand_path('../spec_helper', __FILE__)

describe Cool.io::TimerWatcher do

  interval = 0.010

  let :loop do
    Cool.io::Loop.new
  end

  it "can have the on_timer callback defined after creation" do
    @watcher = Cool.io::TimerWatcher.new(interval, true)
    nr = '0'
    expect(@watcher.on_timer { nr.succ! }).to be_nil
    expect(@watcher.attach(loop)).to eq(@watcher)
    expect(nr).to eq('0')
    sleep interval
    loop.run_once
    expect(nr).to eq('1')
  end

  it "can be subclassed" do
    class MyTimerWatcher < Cool.io::TimerWatcher
      TMP = '0'

      def on_timer
        TMP.succ!
      end
    end
    @watcher = MyTimerWatcher.new(interval, true)
    expect(@watcher.attach(loop)).to eq(@watcher)
    expect(MyTimerWatcher::TMP).to eq('0')
    sleep interval
    loop.run_once
    expect(MyTimerWatcher::TMP).to eq('1')
  end

  it "can have the on_timer callback redefined between runs" do
    @watcher = Cool.io::TimerWatcher.new(interval, true)
    nr = '0'
    expect(@watcher.on_timer { nr.succ! }).to be_nil
    expect(@watcher.attach(loop)).to eq(@watcher)
    expect(nr).to eq('0')
    sleep interval
    loop.run_once
    expect(nr).to eq('1')
    @watcher.detach
    expect(@watcher.on_timer { nr = :foo }).to be_nil
    expect(@watcher.attach(loop)).to eq(@watcher)
    expect(nr).to eq('1')
    sleep interval
    loop.run_once
    expect(nr).to eq(:foo)
  end

  after :each do
    @watcher.detach if defined?(@watcher)
  end
end

Version data entries

45 entries across 45 versions & 6 rubygems

Version Path
cool.io-1.9.0 spec/timer_watcher_spec.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/timer_watcher_spec.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/timer_watcher_spec.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/timer_watcher_spec.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/spec/timer_watcher_spec.rb
cool.io-1.8.0 spec/timer_watcher_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/cool.io-1.7.1/spec/timer_watcher_spec.rb
cool.io-1.7.1-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.7.1-x64-mingw32 spec/timer_watcher_spec.rb
cool.io-1.7.1 spec/timer_watcher_spec.rb
cool.io-1.7.0 spec/timer_watcher_spec.rb
cool.io-1.6.1 spec/timer_watcher_spec.rb
cool.io-1.6.0-x64-mingw32 spec/timer_watcher_spec.rb
cool.io-1.6.0-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.6.0 spec/timer_watcher_spec.rb
cool.io-1.5.4-x64-mingw32 spec/timer_watcher_spec.rb
cool.io-1.5.4-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.5.4 spec/timer_watcher_spec.rb
cool.io-1.5.3-x86-mingw32 spec/timer_watcher_spec.rb
cool.io-1.5.3-x64-mingw32 spec/timer_watcher_spec.rb