Sha256: a9b52897b0d85202a910b17338af6baab8481f433d816a79af2b3b31ba8fa24b

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

#
# Specifying rufus-scheduler
#
# Tue Aug 13 05:58:48 JST 2013
#

require 'spec_helper'


describe Rufus::Scheduler do

  after :each do

    FileUtils.rm_f('.rufus-scheduler.lock')
    FileUtils.rm_f('lock.txt')
  end

  context ':lockfile => ".rufus-scheduler.lock"' do

    it 'writes down a .rufus-scheduler.lock file' do

      s = Rufus::Scheduler.new :lockfile => '.rufus-scheduler.lock'

      line = File.read('.rufus-scheduler.lock')

      #p line
      line.should match(/pid: #{$$}/)
    end

    it '"flocks" the lock file' do

      s = Rufus::Scheduler.new :lockfile => '.rufus-scheduler.lock'

      f = File.new('.rufus-scheduler.lock', 'a')

      f.flock(File::LOCK_NB | File::LOCK_EX).should == false
    end

    it 'prevents newer schedulers from starting' do

      s0 = Rufus::Scheduler.new :lockfile => '.rufus-scheduler.lock'
      s1 = Rufus::Scheduler.new :lockfile => '.rufus-scheduler.lock'

      s0.started_at.should_not == nil
      s1.started_at.should == nil
    end

    it 'releases the lockfile when shutting down' do

      s = Rufus::Scheduler.new :lockfile => '.rufus-scheduler.lock'

      s.shutdown(:kill)

      f = File.new('.rufus-scheduler.lock', 'a')

      f.flock(File::LOCK_NB | File::LOCK_EX).should == 0
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rufus-scheduler-3.0.7 spec/lockfile_spec.rb
rufus-scheduler-3.0.6 spec/lockfile_spec.rb
rufus-scheduler-3.0.5 spec/lockfile_spec.rb
rufus-scheduler-3.0.4 spec/lockfile_spec.rb
rufus-scheduler-3.0.3 spec/lockfile_spec.rb
rufus-scheduler-3.0.2 spec/lockfile_spec.rb
rufus-scheduler-3.0.1 spec/lockfile_spec.rb
rufus-scheduler-3.0.0 spec/lockfile_spec.rb