Commit the pile of initial work. Largely taken from company internal
repos, allowed to be newly released. Portions already in production, coverage still needs to be boosted. Enjoy. FossilOrigin-Name: 0f17fa483f55467bdf9e8f99dace58e6a90f5a8a7e595bdd79dfda5c92d16b7f
This commit is contained in:
commit
b18647f6a5
23 changed files with 2639 additions and 0 deletions
130
spec/symphony/tasks/scheduletask_spec.rb
Normal file
130
spec/symphony/tasks/scheduletask_spec.rb
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/env rspec -wfd
|
||||
# vim: set nosta noet ts=4 sw=4:
|
||||
|
||||
require_relative '../../helpers'
|
||||
|
||||
describe Symphony::Metronome::ScheduleTask do
|
||||
|
||||
let( :time ) { Time.at(1262376000) }
|
||||
let( :db ) { double('sequel db handle') }
|
||||
let( :actions ) { double('sequel dataset') }
|
||||
|
||||
before( :each ) do
|
||||
allow( Symphony::Metronome::ScheduledEvent ).to receive( :db ).and_return( db )
|
||||
allow( db ).to receive( :[] ).with( :metronome ).and_return( actions )
|
||||
Timecop.freeze( time )
|
||||
end
|
||||
|
||||
context 'creating a new event' do
|
||||
|
||||
let( :task ) { described_class.new(nil) }
|
||||
let( :metadata ) {
|
||||
{
|
||||
:delivery_info => double( 'delivery info' ),
|
||||
:properties => double( 'properties' )
|
||||
}
|
||||
}
|
||||
|
||||
it 'fails with non-hash payloads' do
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.create' )
|
||||
|
||||
expect {
|
||||
task.work( [], metadata )
|
||||
}.to raise_error( ArgumentError, 'Invalid payload.' )
|
||||
end
|
||||
|
||||
it 'fails without an expression argument' do
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.create' )
|
||||
|
||||
expect {
|
||||
task.work( {}, metadata )
|
||||
}.to raise_error( ArgumentError, 'Missing time expression.' )
|
||||
end
|
||||
|
||||
it 'saves the event and seralized options to storage' do
|
||||
allow( Process ).to receive( :ppid ).and_return( 12000 )
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.create' )
|
||||
|
||||
payload = {
|
||||
'expression' => 'at 2pm',
|
||||
'excitement_level' => 12
|
||||
}
|
||||
|
||||
expect( actions ).to receive( :insert ).with({
|
||||
:created => time,
|
||||
:expression => 'at 2pm',
|
||||
:options => '{"excitement_level":12}'
|
||||
})
|
||||
expect( Process ).to receive( :kill ).with( 'HUP', 12000 )
|
||||
|
||||
expect( task.work(payload, metadata) ).to be_truthy
|
||||
end
|
||||
|
||||
it 'exits if it has become an orphaned process' do
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.create' )
|
||||
|
||||
payload = {
|
||||
'expression' => 'at 2pm',
|
||||
'excitement_level' => 12
|
||||
}
|
||||
|
||||
expect( actions ).to receive( :insert ).with({
|
||||
:created => time,
|
||||
:expression => 'at 2pm',
|
||||
:options => '{"excitement_level":12}'
|
||||
})
|
||||
expect( Process ).to_not receive( :kill )
|
||||
|
||||
# parent gone! init takes over.
|
||||
allow( Process ).to receive( :ppid ).and_return( 1 )
|
||||
|
||||
expect { task.work( payload, metadata ) }.to raise_error( SystemExit )
|
||||
end
|
||||
end
|
||||
|
||||
context 'removing an existing event' do
|
||||
|
||||
let( :task ) { described_class.new(nil) }
|
||||
let( :metadata ) {
|
||||
{
|
||||
:delivery_info => double( 'delivery info' ),
|
||||
:properties => double( 'properties' )
|
||||
}
|
||||
}
|
||||
|
||||
it 'removes rows matching the payload ID' do
|
||||
allow( Process ).to receive( :ppid ).and_return( 12000 )
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.delete' )
|
||||
|
||||
payload = "44"
|
||||
row = double( 'filtered dataaset' )
|
||||
expect( row ).to receive( :delete )
|
||||
expect( actions ).to receive( :filter ).with( :id => 44 ).and_return( row )
|
||||
expect( Process ).to receive( :kill ).with( 'HUP', 12000 )
|
||||
|
||||
task.work( payload, metadata )
|
||||
end
|
||||
|
||||
it 'exits if it has become an orphaned process' do
|
||||
expect( metadata[:delivery_info] ).to receive( :routing_key ).
|
||||
and_return( 'metronome.delete' )
|
||||
|
||||
payload = "44"
|
||||
row = double( 'filtered dataaset' )
|
||||
expect( row ).to receive( :delete )
|
||||
expect( actions ).to receive( :filter ).with( :id => 44 ).and_return( row )
|
||||
expect( Process ).to_not receive( :kill )
|
||||
|
||||
# parent gone! init takes over.
|
||||
allow( Process ).to receive( :ppid ).and_return( 1 )
|
||||
|
||||
expect { task.work( payload, metadata ) }.to raise_error( SystemExit )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue