test/LockFile_spec.rb in perobs-4.0.0 vs test/LockFile_spec.rb in perobs-4.1.0
- old
+ new
@@ -28,11 +28,15 @@
require 'perobs/LockFile'
describe PEROBS::LockFile do
before(:each) do
- @dir = Dir.mktmpdir('LockFile')
+ PEROBS.log.open($stderr)
+ PEROBS.log.level = Logger::INFO
+ @dir = File.join(Dir.tmpdir,
+ "#{File.basename('LockFile_spec')}.#{rand(2**32)}")
+ FileUtils.mkdir_p(@dir)
@file = File.join(@dir, 'LockFile.lock')
end
after(:each) do
FileUtils.rm_rf(@dir)
@@ -40,11 +44,10 @@
it 'should raise an error if the lock file directory does not exist' do
capture_io do
expect(PEROBS::LockFile.new('/foo/bar/foobar').lock).to be false
end
- PEROBS.log.open($stderr)
end
it 'should support taking and releasing the lock' do
lock = PEROBS::LockFile.new(@file)
expect(lock.is_locked?).to be false
@@ -57,19 +60,19 @@
lock = PEROBS::LockFile.new(@file)
expect(lock.lock).to be true
expect(lock.is_locked?).to be true
lock.forced_unlock
expect(lock.is_locked?).to be false
- out = capture_io{ expect(lock.unlock).to be false }
+ out = capture_io{ expect(lock.unlock).to be false }.log
expect(out).to include('There is no current lock to release')
end
it 'should fail if the lock is already taken' do
lock1 = PEROBS::LockFile.new(@file)
expect(lock1.lock).to be true
lock2 = PEROBS::LockFile.new(@file)
- out = capture_io { expect(lock2.lock).to be false }
+ out = capture_io { expect(lock2.lock).to be false }.log
expect(out).to include('due to timeout')
expect(lock1.unlock).to be true
expect(lock2.lock).to be true
expect(lock2.unlock).to be true
end
@@ -103,11 +106,11 @@
while !File.exist?(@file)
sleep 1
end
lock2 = PEROBS::LockFile.new(@file,
{ :max_retries => 2, :pause_secs => 0.5 })
- out = capture_io { expect(lock2.lock).to be false }
+ out = capture_io { expect(lock2.lock).to be false }.log
expect(out).to include('due to timeout')
Process.wait(pid)
end
it 'should terminate the old lockholder after timeout' do
@@ -121,10 +124,10 @@
while !File.exist?(@file)
sleep 1
end
lock2 = PEROBS::LockFile.new(@file, { :timeout_secs => 1 })
- out = capture_io { expect(lock2.lock).to be true }
+ out = capture_io { expect(lock2.lock).to be true }.log
expect(out).to include('Old lock file found for PID')
expect(lock2.unlock).to be true
Process.wait(pid)
end