Add additional recurring event tests.

FossilOrigin-Name: acf33e24ffa73e09b61f5a7e1e8dadc4afed94dfe8b1d7eef7653f30e82090a1
This commit is contained in:
mahlon@laika.com 2014-10-28 21:29:25 +00:00
parent 22eae27d60
commit f3c9b10b95
4 changed files with 41 additions and 4 deletions

View file

@ -4,3 +4,4 @@ sqlite3 -v1.3.9
symphony -v0.6.0
rspec -v3.0.0.beta2
timecop -v0.7.1
simplecov -v0.9.1

View file

@ -2,7 +2,7 @@
SimpleCov.start do
add_filter 'spec'
add_filter 'integration'
add_filter 'migrations'
add_group "Needing tests" do |file|
file.covered_percent < 90
end

View file

@ -126,7 +126,7 @@ class Symphony::Metronome::Scheduler
end
### Process all event that have reached their runtime.
### Process all events that have reached their runtime.
###
def process_events
now = Time.now

View file

@ -107,6 +107,22 @@ describe Symphony::Metronome::ScheduledEvent do
expect( ev.runtime ).to be >= time + 3600 + 30
end
it 'can reschedule itself into the future when recurring (recently run)' do
ds.insert(
:created => time,
:expression => 'every 30 seconds',
:options => "",
:lastrun => time - 12
)
ev = described_class.new( ds.first )
Timecop.travel( time ) do
ev.reset_runtime
end
expect( ev.runtime ).to be >= time + 18
end
it 'removes itself when firing if expired' do
ds.insert(
:created => time,
@ -134,6 +150,26 @@ describe Symphony::Metronome::ScheduledEvent do
expect( res ).to be( 12 )
end
it "won't re-fire recurring events if they already fired within their interval window" do
ds.insert(
:created => time,
:expression => 'every 30 seconds',
:options => '{"excitement_level":12}',
:lastrun => time - 12
)
ev = described_class.new( ds.first )
res = 0
Timecop.travel( time ) do
rv = ev.fire do |opts, id|
res = opts['excitement_level']
end
expect( rv ).to be_falsey
end
expect( res ).to be( 0 )
end
it 'randomizes start times if a splay is configured' do
described_class.instance_variable_set( :@splay, 5 )