Sha256: 869ee4552cf6bba6dc899bee674dfffb4c9d8a7ee7a14442412a63a68f43cc4b

Contents?: true

Size: 894 Bytes

Versions: 13

Compression:

Stored size: 894 Bytes

Contents

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

require 'rbbt-util'
require 'rbbt/util/log'
require 'rbbt/util/concurrency/processes'

class TestConcurrencyProcess < Test::Unit::TestCase

  def test_process
    q = RbbtProcessQueue.new 10

    res = []

    q.callback do |v|
      res << v
    end

    q.init do |i|
      i * 2
    end

    times = 500
    t = TSV.setup({"a" => 1}, :type => :single)

    times.times do |i|
      q.process i
    end

    q.join
    q.clean

    assert_equal times, res.length
    assert_equal [0, 2, 4], res.sort[0..2]
  end

  def test_each
    times = 5000
    elems = (0..times-1).to_a

    TmpFile.with_file do |dir|
      RbbtProcessQueue.each(elems) do |elem|
        Open.write(File.join(dir, elem.to_s), "DONE")
      end

      assert_equal times, Dir.glob(File.join(dir, '*')).length
    end
  end
end


Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rbbt-util-5.10.1 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.12 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.11 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.10 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.8 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.7 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.6 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.5 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.4 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.3 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.2 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.1 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.9.0 test/rbbt/util/concurrency/test_processes.rb