Sha256: bff158b881c38edf9bae6fb2d54eb946f84eaf7c6daf9aa345acc8d69008bc0b

Contents?: true

Size: 1.38 KB

Versions: 22

Compression:

Stored size: 1.38 KB

Contents

require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')

require 'scout/tmpfile'

class TestLock < Test::Unit::TestCase
  def test_locks
    num = 10
    TmpFile.with_file do |lockfile|
      TmpFile.with_file do |output|
        f = File.open(output, 'w') 
        thrs = num.times.collect do 
          Thread.new do
            Open.lock lockfile, true, min_sleep: 0.01, max_sleep: 0.05, sleep_inc: 0.001 do
              f.write "["
              sleep 0.01
              f.write "]"
            end
          end
        end
        thrs.each{|t| t.join }
        f.close
        assert_equal "[]" * num, File.open(output).read 
      end
    end
  end

  def test_keep_locked
    num = 10
    TmpFile.with_file do |lockfile|
      TmpFile.with_file do |output|
        f = File.open(output, 'w') 
        thrs = num.times.collect do 
          Thread.new do
            lock = Lockfile.new(lockfile, min_sleep: 0.01, max_sleep: 0.05, sleep_inc: 0.001)
            res = Open.lock lock do
              f.write "["
              raise KeepLocked, "1"
            end
            f.write res
            f.write "]"
            lock.unlock
          end
        end
        thrs.each{|t| t.join }
        f.close
        assert_equal "[1]" * num, File.open(output).read 
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
scout-essentials-1.6.5 test/scout/open/test_lock.rb
scout-essentials-1.6.4 test/scout/open/test_lock.rb
scout-essentials-1.6.3 test/scout/open/test_lock.rb
scout-essentials-1.6.2 test/scout/open/test_lock.rb
scout-essentials-1.6.1 test/scout/open/test_lock.rb
scout-essentials-1.6.0 test/scout/open/test_lock.rb
scout-essentials-1.3.1 test/scout/open/test_lock.rb
scout-essentials-1.3.0 test/scout/open/test_lock.rb
scout-essentials-1.2.0 test/scout/open/test_lock.rb
scout-essentials-1.1.1 test/scout/open/test_lock.rb
scout-essentials-1.1.0 test/scout/open/test_lock.rb
scout-essentials-1.0.0 test/scout/open/test_lock.rb
scout-gear-9.1.0 test/scout/open/test_lock.rb
scout-gear-9.0.0 test/scout/open/test_lock.rb
scout-gear-8.1.0 test/scout/open/test_lock.rb
scout-gear-8.0.0 test/scout/open/test_lock.rb
scout-gear-7.3.0 test/scout/open/test_lock.rb
scout-gear-7.2.0 test/scout/open/test_lock.rb
scout-gear-7.1.0 test/scout/open/test_lock.rb
scout-gear-6.0.0 test/scout/open/test_lock.rb