Permalink
Browse files

fixed test cases

  • Loading branch information...
1 parent cb3ade7 commit 577e7fa662ff4070952f83e9805b979a30f1b13d @frsyuki frsyuki committed May 18, 2012
Showing with 31 additions and 23 deletions.
  1. +8 −0 lib/perfectsched/command/perfectsched.rb
  2. +1 −1 lib/perfectsched/worker.rb
  3. +19 −19 spec/schedule_collection_spec.rb
  4. +3 −3 spec/worker_spec.rb
@@ -17,6 +17,7 @@
env = ENV['RAILS_ENV'] || 'development'
config_path = 'config/perfectsched.yml'
+include_dirs = []
require_files = []
add_options = {
@@ -56,6 +57,10 @@
op.separator("\noptions for run:")
+op.on('-I', '--include PATH', 'Add $LOAD_PATH directory') {|s|
+ include_dirs << s
+}
+
op.on('-r', '--require PATH', 'Require files before starting') {|s|
require_files << s
}
@@ -147,6 +152,9 @@
}
when :run
+ include_dirs.each {|path|
+ $LOAD_PATH << File.expand_path(path)
+ }
require_files.each {|file|
require file
}
@@ -59,7 +59,7 @@ def stop
@log.info "stop"
begin
@finished = true
- @engine.stop
+ @engine.stop if @engine
rescue
@log.error "failed to stop: #{$!}"
$!.backtrace.each {|bt| @log.warn "\t#{bt}" }
@@ -12,26 +12,26 @@
@sc.class.should == PerfectSched::ScheduleCollection
end
- it 'succeess submit' do
- @sc.submit('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
+ it 'succeess add' do
+ @sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
end
- it 'fail duplicated submit' do
- @sc.submit('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
+ it 'fail duplicated add' do
+ @sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
lambda {
- @sc.submit('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
+ @sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
}.should raise_error AlreadyExistsError
@sc['sched01'].delete!
- @sc.submit('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
+ @sc.add('sched01', 't01', {:cron=>'* * * * *', :timezone=>'UTC'})
end
it 'acquire' do
time = 1323820800 # 2011-12-14 00:00:00 UTC
- s01 = @sc.submit('sched01', 't01', :cron=>"* * * * *", :data=>{'k'=>1}, :next_time=>time)
+ s01 = @sc.add('sched01', 't01', :cron=>"* * * * *", :data=>{'k'=>1}, :next_time=>time)
t01 = @sc.poll(:alive_time=>120, :now=>time)
t01.key.should == 'sched01'
@@ -58,11 +58,11 @@
it 'timezone' do
time = 1323820800 # 2011-12-14 00:00:00 UTC
- s01 = @sc.submit('sched01', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'UTC')
+ s01 = @sc.add('sched01', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'UTC')
#s01.class.should == Schedule
#s01.key.should == 'sched01'
- s02 = @sc.submit('sched02', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'Asia/Tokyo')
+ s02 = @sc.add('sched02', 't01', :cron=>"0 0 * * *", :next_time=>time-60, :timezone=>'Asia/Tokyo')
#s02.class.should == Schedule
#s02.key.should == 'sched02'
@@ -82,7 +82,7 @@
it 'delay' do
time = 1323820800 # 2011-12-14 00:00:00 UTC
- s01 = @sc.submit('sched01', 't01', :cron=>"0 * * * *", :delay=>30, :next_time=>time, :timezone=>'UTC')
+ s01 = @sc.add('sched01', 't01', :cron=>"0 * * * *", :delay=>30, :next_time=>time, :timezone=>'UTC')
t01 = @sc.poll(:alive_time=>86400, :now=>time)
t01.should == nil
@@ -109,31 +109,31 @@
it 'invalid cron format' do
lambda {
- @sc.submit('sched01', 't01', :cron=>'???')
+ @sc.add('sched01', 't01', :cron=>'???')
}.should raise_error ArgumentError
lambda {
- @sc.submit('sched01', 't01', :cron=>'* * * * * *')
+ @sc.add('sched01', 't01', :cron=>'* * * * * *')
}.should raise_error ArgumentError
end
- it 'fail duplicated submit' do
- @sc.submit('sched01', 't01', :cron=>"0 * * * *")
+ it 'fail duplicated add' do
+ @sc.add('sched01', 't01', :cron=>"0 * * * *")
lambda {
- @sc.submit('sched01', 't01', :cron=>"0 * * * *")
+ @sc.add('sched01', 't01', :cron=>"0 * * * *")
}.should raise_error AlreadyExistsError
@sc['sched01'].delete!
- @sc.submit('sched01', 't01', :cron=>"0 * * * *")
+ @sc.add('sched01', 't01', :cron=>"0 * * * *")
end
it 'list' do
time = 1323820800 # 2011-12-14 00:00:00 UTC
- @sc.submit('sched01', 't01', :cron=>"0 * * * *", :next_time=>time, :delay=>1)
- @sc.submit('sched02', 't02', :cron=>"0 * * * *", :next_time=>time, :delay=>2)
- @sc.submit('sched03', 't03', :cron=>"0 * * * *", :next_time=>time, :delay=>3, :next_run_time=>time+3600)
+ @sc.add('sched01', 't01', :cron=>"0 * * * *", :next_time=>time, :delay=>1)
+ @sc.add('sched02', 't02', :cron=>"0 * * * *", :next_time=>time, :delay=>2)
+ @sc.add('sched03', 't03', :cron=>"0 * * * *", :next_time=>time, :delay=>3, :next_run_time=>time+3600)
a = []
@sc.list {|s|
View
@@ -48,17 +48,17 @@ def self.new(task)
@thread.join
end
- def submit(*args)
+ def add(*args)
sc = get_test_sched
- sc.submit(*args)
+ sc.add(*args)
sc.close
end
it 'run' do
TestApp.later do
TestHandler.any_instance.should_receive(:run).once
end
- submit('key', 'test', {:cron=>'* * * * *', :next_time=>Time.now.to_i-60})
+ add('key', 'test', {:cron=>'* * * * *', :next_time=>Time.now.to_i-60})
sleep 2
end

0 comments on commit 577e7fa

Please sign in to comment.