Sha256: afabab7aa1c3bd4ae7622d2f31addab0fdc932e41efb0ee7bcbfc7d70bff37a6
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
require 'fileutils' require 'timeout' root = File.expand_path(File.join(File.dirname(__FILE__), '..')) cmd = File.join root, 'bin/cron_wrapper' def remove_lock FileUtils.rm_f "tmp/locks/awesome_script.lock" rescue nil end describe "cron_wrapper" do before(:all) do FileUtils.mkdir_p "#{root}/tmp/locks" FileUtils.mkdir_p "#{root}/log" FileUtils.mkdir_p "#{root}/lib/cron" File.open("#{root}/lib/cron/awesome_script.rb", 'w') do |file| file. << 'sleep(1); puts "awesome"' end end before(:each) do @pid = nil remove_lock end after(:all) do FileUtils.rm_rf "#{root}/tmp" FileUtils.rm_rf "#{root}/log" FileUtils.rm_rf "#{root}/lib/cron" end it "should create a lock file in lock_dir if no lock file exists" do t = Thread.new { `#{cmd} --wrap awesome_script --wrap-verbose --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log` } Timeout::timeout(2) do begin @pid = File.read "#{root}/tmp/locks/awesome_script.lock" rescue retry end end.should_not raise_error TimeoutError @pid.nil?.should_not == true t.join end it "should remove the lock file in lock_dir after execution" do `#{cmd} --wrap awesome_script --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log` File.exists?("tmp/locks/awesome_script.lock").should == false end it "should have the pid of the currently executing thread in the lock file" do read_pid = nil @pid = Process.fork { `#{cmd} --wrap awesome_script --wrap-verbose --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log` } begin read_pid = File.read "#{root}/tmp/locks/awesome_script.lock" rescue retry end Process.wait read_pid.should == (@pid + 1).to_s end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cron_wrapper-0.0.8 | spec/cron_wrapper_spec.rb |
cron_wrapper-0.0.7 | spec/cron_wrapper_spec.rb |
cron_wrapper-0.0.6 | spec/cron_wrapper_spec.rb |