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.34.16 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.15 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.14 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.13 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.12 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.11 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.10 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.9 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.8 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.7 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.5 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.4 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.3 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.2 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.1 test/rbbt/util/test_semaphore.rb
rbbt-util-5.34.0 test/rbbt/util/test_semaphore.rb
rbbt-util-5.33.21 test/rbbt/util/test_semaphore.rb
rbbt-util-5.33.20 test/rbbt/util/test_semaphore.rb
rbbt-util-5.33.19 test/rbbt/util/test_semaphore.rb
rbbt-util-5.33.18 test/rbbt/util/test_semaphore.rb