Sha256: bcff0c46569eb9f75b85a90e0ab4d3214f77aabe31e01aaa0f81053ec5bc6469
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
require 'spec_helper' module Concurrent describe '#timer' do it 'raises an exception when no block given' do expect { Concurrent::timer(0.1) }.to raise_error(ArgumentError) end it 'raises an exception if the interval is less than 0 seconds' do expect { Concurrent::timer(-1){ :foo } }.to raise_error(ArgumentError) end it 'executes the block after the given number of seconds' do start = Time.now expected = Concurrent::AtomicFixnum.new(0) Concurrent::timer(0.5){ expected.increment } expected.value.should eq 0 sleep(0.1) expected.value.should eq 0 sleep(0.8) expected.value.should eq 1 end it 'suppresses exceptions thrown by the block' do expect { Concurrent::timer(0.5){ raise Exception } }.to_not raise_error end it 'passes all arguments to the block' do expected = nil latch = CountDownLatch.new(1) Concurrent::timer(0, 1, 2, 3) do |*args| expected = args latch.count_down end latch.wait(0.2) expected.should eq [1, 2, 3] end it 'runs the task on the global timer pool' do Concurrent.configuration.global_timer_set.should_receive(:post).with(0.1) Concurrent::timer(0.1){ :foo } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
concurrent-ruby-0.6.0.pre.2 | spec/concurrent/utility/timer_spec.rb |