File: strict_spec.rb

package info (click to toggle)
ruby-timers 4.1.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 196 kB
  • sloc: ruby: 668; makefile: 7
file content (37 lines) | stat: -rw-r--r-- 814 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

require 'spec_helper'

RSpec.describe Timers::Group do
	it "should not diverge too much" do
		fired = :not_fired_yet
		count = 0
		quantum = 0.01
		
		start_offset = subject.current_offset
		Timers::Timer.new(subject, quantum, :strict, start_offset) do |offset|
			fired = offset
			count += 1
		end
		
		iterations = 1000
		subject.wait while count < iterations
		
		# In my testing on the JVM, without the :strict recurring, I noticed 60ms of error here.
		expect(fired - start_offset).to be_within(quantum).of(iterations * quantum)
	end
	
	it "should only fire once" do
		fired = :not_fired_yet
		count = 0

		start_offset = subject.current_offset
		Timers::Timer.new(subject, 0, :strict, start_offset) do |offset|
			fired = offset
			count += 1
		end
		
		subject.wait
		
		expect(count).to be == 1
	end
end