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.43.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.42.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.41.1 test/rbbt/util/test_semaphore.rb
rbbt-util-5.41.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.40.5 test/rbbt/util/test_semaphore.rb
rbbt-util-5.40.4 test/rbbt/util/test_semaphore.rb
rbbt-util-5.40.3 test/rbbt/util/test_semaphore.rb
rbbt-util-5.40.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.39.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.38.1 test/rbbt/util/test_semaphore.rb
rbbt-util-5.38.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.16 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.15 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.14 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.13 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.12 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.11 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.10 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.9 test/rbbt/util/test_semaphore.rb
rbbt-util-5.37.8 test/rbbt/util/test_semaphore.rb