Sha256: ebeb513328571282fd9bf249a4895f01b74fcc85ca1b01184476f39bcec87a87

Contents?: true

Size: 1.25 KB

Versions: 54

Compression:

Stored size: 1.25 KB

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

    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

  def test_process_abort
    assert_raise Aborted do
      q = RbbtProcessQueue.new 10

      res = []

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

      q.init do |i|
        sleep 1 while true
      end

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

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

      sleep 2
      q.clean

      q.join
    end
  end
end


Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
rbbt-util-5.14.18 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.17 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.16 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.15 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.14 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.12 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.11 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.10 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.9 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.8 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.7 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.6 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.5 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.4 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.3 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.2 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.1 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.14.0 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.13.37 test/rbbt/util/concurrency/test_processes.rb
rbbt-util-5.13.36 test/rbbt/util/concurrency/test_processes.rb