<commit_before>
#
# Testing Ruote (OpenWFEru)
#
# Wed Jul  8 15:30:55 JST 2009
#

require File.join(File.dirname(__FILE__), 'base')

require 'ruote/part/hash_participant'


class CtConcurrenceTest < Test::Unit::TestCase
  include FunctionalBase

  class Ruote::HashParticipant
    # removes first available workitem from hash
    def pop
      @items.delete(@items.keys.first)
    end
  end

  def setup

    @tracer = Tracer.new

    @engine0 = start_new_engine
    @engine1 = start_new_engine

    change_concurrence_expression
  end

  def teardown

    @engine0.shutdown
    @engine1.shutdown

    FileUtils.rm_rf('work')

    unchange_concurrence_expression
      # play nice with other tests
  end

  def test_no_collision

    pdef = Ruote.process_definition do
      concurrence do
        alpha
        alpha
      end
    end

    alpha0 = @engine0.register_participant :alpha, Ruote::HashParticipant
    alpha1 = @engine1.register_participant :alpha, Ruote::HashParticipant

    wfid = @engine0.launch(pdef)

    sleep 0.100

    assert_not_nil @engine0.process(wfid)
    assert_not_nil @engine0.process(wfid)

    assert_equal 2, alpha0.size
    assert_equal 0, alpha1.size

    @engine1.reply(alpha0.pop)
    sleep 0.100
    @engine0.reply(alpha0.pop)
    sleep 0.100

    assert_equal nil, @engine0.process(wfid)
    assert_equal nil, @engine1.process(wfid)
  end

  def test_collision

    pdef = Ruote.process_definition do
      concurrence do
        alpha
        alpha
      end
    end

    alpha0 = @engine0.register_participant :alpha, Ruote::HashParticipant
    alpha1 = @engine1.register_participant :alpha, Ruote::HashParticipant

    wfid = @engine0.launch(pdef)

    sleep 0.100

    @engine1.reply(alpha0.pop)
      # and immediately...
    @engine0.reply(alpha0.pop)

    sleep 0.100

    assert_nil @engine0.process(wfid)
    assert_nil @engine1.process(wfid)

    #puts `tree work/`
  end

  protected

  def start_new_engine

    ac = {}
<commit_msg>giving some time to ruote-dm<commit_after>
#
# Testing Ruote (OpenWFEru)
#
# Wed Jul  8 15:30:55 JST 2009
#

require File.join(File.dirname(__FILE__), 'base')

require 'ruote/part/hash_participant'


class CtConcurrenceTest < Test::Unit::TestCase
  include FunctionalBase

  class Ruote::HashParticipant
    # removes first available workitem from hash
    def pop
      @items.delete(@items.keys.first)
    end
  end

  def setup

    @tracer = Tracer.new

    @engine0 = start_new_engine
    @engine1 = start_new_engine

    change_concurrence_expression
  end

  def teardown

    @engine0.shutdown
    @engine1.shutdown

    FileUtils.rm_rf('work')

    unchange_concurrence_expression
      # play nice with other tests
  end

  def test_no_collision

    pdef = Ruote.process_definition do
      concurrence do
        alpha
        alpha
      end
    end

    alpha0 = @engine0.register_participant :alpha, Ruote::HashParticipant
    alpha1 = @engine1.register_participant :alpha, Ruote::HashParticipant

    wfid = @engine0.launch(pdef)

    sleep 0.200

    assert_not_nil @engine0.process(wfid)
    assert_not_nil @engine0.process(wfid)

    assert_equal 2, alpha0.size
    assert_equal 0, alpha1.size

    @engine1.reply(alpha0.pop)
    sleep 0.200
    @engine0.reply(alpha0.pop)
    sleep 0.200

    assert_equal nil, @engine0.process(wfid)
    assert_equal nil, @engine1.process(wfid)
  end

  def test_collision

    pdef = Ruote.process_definition do
      concurrence do
        alpha
        alpha
      end
    end

    alpha0 = @engine0.register_participant :alpha, Ruote::HashParticipant
    alpha1 = @engine1.register_participant :alpha, Ruote::HashParticipant

    wfid = @engine0.launch(pdef)

    sleep 0.200

    @engine1.reply(alpha0.pop)
      # and immediately...
    @engine0.reply(alpha0.pop)

    sleep 0.200

    assert_nil @engine0.process(wfid)
    assert_nil @engine1.process(wfid)

    #puts `tree work/`
  end

  protected

  def start_new_engine

    ac = {}

{'fraction_non_alphanumeric': 0.08314493845767396, 'fraction_numerical': 0.031650339110776186, 'mean_word_length': 2.9347826086956523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1063462', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1327, 'n_words': 288}