Sha256: 2f1c2d06fe7a0157901d53d3ddd670224da72bf46655cce10dd10f6690aace5c

Contents?: true

Size: 859 Bytes

Versions: 758

Compression:

Stored size: 859 Bytes

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
require 'rbbt/util/semaphore'

class TestRbbtSemaphore < Test::Unit::TestCase
  def test_process
    RbbtSemaphore.with_semaphore(10) do |s|
      pids = []
      100.times do 
        pids << Process.fork do
          100.times do
            RbbtSemaphore.wait_semaphore(s)
            sleep 0.001
            RbbtSemaphore.post_semaphore(s)
          end
        end
      end
      pids.each do |pid|
        Process.waitpid pid
      end
    end
  end

  def _test_thread
    times = 50
    TmpFile.with_file do |dir|
      Path.setup(dir)
      FileUtils.mkdir_p dir
      RbbtSemaphore.thread_each_on_semaphore((1..times).to_a, 25){|elem|
        sleep rand
        Open.write(dir[elem], "test")
      }
      assert_equal times, dir.glob.length
    end
  end
end

Version data entries

758 entries across 758 versions & 1 rubygems

Version Path
rbbt-util-5.32.26 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.25 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.24 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.23 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.22 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.21 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.20 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.18 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.17 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.16 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.15 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.13 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.12 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.11 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.10 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.9 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.7 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.6 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.5 test/rbbt/util/test_semaphore.rb
rbbt-util-5.32.4 test/rbbt/util/test_semaphore.rb