test/functional/eft_6_concurrence.rb in ruote-2.2.0 vs test/functional/eft_6_concurrence.rb in ruote-2.3.0
- old
+ new
@@ -3,15 +3,13 @@
# testing ruote
#
# Thu Jun 11 15:24:47 JST 2009
#
-require File.join(File.dirname(__FILE__), 'base')
+require File.expand_path('../base', __FILE__)
-#require 'ruote/part/hash_participant'
-
class EftConcurrenceTest < Test::Unit::TestCase
include FunctionalBase
def test_basic
@@ -20,19 +18,44 @@
alpha
alpha
end
end
- @engine.register_participant :alpha do
- @tracer << "alpha\n"
+ @dashboard.register_participant :alpha do
+ tracer << "alpha\n"
end
- #noisy
-
assert_trace %w[ alpha alpha ], pdef
end
+ def test_empty
+
+ pdef = Ruote.process_definition do
+ concurrence do
+ end
+ echo 'done.'
+ end
+
+ assert_trace %w[ done. ], pdef
+ end
+
+ def test_accidental_empty
+
+ @dashboard.register_participant :nada do
+ tracer << "nada\n"
+ end
+
+ pdef = Ruote.process_definition do
+ concurrence do
+ nada :if => false
+ end
+ echo 'done.'
+ end
+
+ assert_trace %w[ done. ], pdef
+ end
+
def test_over_if
pdef = Ruote.process_definition do
concurrence :over_if => "${f:seen}", :merge_type => :isolate do
alpha
@@ -40,41 +63,94 @@
alpha
end
bravo
end
- @engine.context.instance_eval do
- @count = 0
- end
- # since block participants are evaluated in the context context
+ stash[:count] = 0
- alpha = @engine.register_participant :alpha, 'do_not_thread' => true do |wi|
- wi.fields['seen'] = 'indeed' if @count == 1
- @tracer << "alpha\n"
- @count = @count + 1
+ alpha = @dashboard.register :alpha, 'do_not_thread' => true do |wi|
+ wi.fields['seen'] = 'indeed' if stash[:count] == 1
+ tracer << "alpha\n"
+ stash[:count] += 1
nil
end
- @engine.register_participant :bravo do |workitem|
+ @dashboard.register_participant :bravo do |workitem|
stash[:fields] = workitem.fields
nil
end
- #noisy
-
assert_trace(%w[ alpha ] * 3, pdef)
#assert_equal(
# {'1'=>{"seen"=>"indeed"}, '0'=>{}, "params"=>{"ref"=>"bravo"}},
# fields)
- params = @engine.context.stash[:fields].delete('params')
+ params = @dashboard.context.stash[:fields].delete('params')
assert_equal({ 'ref' => 'bravo' }, params)
- assert_match /seen/, @engine.context.stash[:fields].inspect
+ assert_match /seen/, @dashboard.context.stash[:fields].inspect
end
+ def test_over_if__remaining_cancel
+
+ @dashboard.register 'alpha', Ruote::StorageParticipant
+
+ pdef = Ruote.define do
+ concurrence :over_if => '${seen}' do
+ alpha
+ alpha
+ end
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ @dashboard.wait_for('dispatched')
+
+ wi = @dashboard.storage_participant.first
+
+ wi.fields['seen'] = true
+ @dashboard.storage_participant.proceed(wi)
+
+ @dashboard.wait_for('dispatch_cancel')
+ sleep 0.350
+
+ assert_equal 0, @dashboard.storage_participant.size
+ end
+
+ def test_over_if__post
+
+ @dashboard.register :alpha do |workitem|
+ tracer << "alpha\n"
+ workitem.fields['ok'] = 'yes'
+ end
+ @dashboard.register :bravo do |workitem|
+ sleep 0.5
+ tracer << "bravo\n"
+ end
+ @dashboard.register :zulu do |workitem|
+ tracer << "zulu\n"
+ end
+
+ pdef = Ruote.define do
+ set 'f:ok' => 'no'
+ concurrence :over_if => '${f:ok} == yes' do
+ #concurrence :over_if => '${f:ok} == yes', :merge_type => 'mix' do
+ alpha
+ bravo :if => 'false'
+ end
+ zulu :if => '${f:ok} == yes'
+ end
+
+ wfid = @dashboard.launch(pdef)
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal 'terminated', r['action']
+ assert_equal 'yes', r['workitem']['fields']['ok']
+ assert_equal %w[ alpha zulu ], @tracer.to_a
+ end
+
def test_over_unless
pdef = Ruote.process_definition do
set 'f:ok' => 'true'
concurrence :over_unless => '${f:ok}', :merge_type => :isolate do
@@ -83,32 +159,27 @@
alpha
end
echo 'done.'
end
- @engine.context.instance_eval do
- @count = 0
- end
- # since block participants are evaluated in the context context
+ stash[:count] = 0
- alpha = @engine.register_participant :alpha, 'do_not_thread' => true do |wi|
- if @count > 1
+ alpha = @dashboard.register :alpha, 'do_not_thread' => true do |wi|
+ if stash[:count] > 1
wi.fields['ok'] = false
else
- @tracer << "a\n"
- @count = @count + 1
+ tracer << "a\n"
+ stash[:count] += 1
end
end
fields = nil
- @engine.register_participant :bravo do |workitem|
+ @dashboard.register_participant :bravo do |workitem|
fields = workitem.fields
end
- #noisy
-
assert_trace(%w[ a a done. ], pdef)
end
def test_remaining_forget_when_no_remains
@@ -118,12 +189,10 @@
echo 'b'
end
echo 'done.'
end
- #noisy
-
assert_trace %w[ a b done. ], %w[ b a done. ], pdef
end
# helper
#
@@ -137,30 +206,30 @@
end
end
alpha
end
- alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
+ alpha = @dashboard.register_participant :alpha, Ruote::StorageParticipant
noisy if noise
- wfid = @engine.launch(pdef)
+ wfid = @dashboard.launch(pdef)
wait_for(:alpha)
wait_for(:alpha)
2.times do
wi = alpha.first
wi.fields['seen'] = wi.fei.expid
- alpha.reply(wi)
+ alpha.proceed(wi)
end
wait_for(:alpha)
wi = alpha.first
- ps = @engine.process(wi.fei.wfid)
+ ps = @dashboard.process(wi.fei.wfid)
assert_equal %w[ 0 0_1 ], ps.expressions.collect { |e| e.fei.expid }.sort
wi
end
@@ -215,90 +284,260 @@
alpha
bravo
end
end
- @engine.register_participant '.+', Ruote::StorageParticipant
+ @dashboard.register_participant '.+', Ruote::StorageParticipant
noisy if noise
- wfid = @engine.launch(pdef)
+ wfid = @dashboard.launch(pdef)
wait_for(:alpha)
- @engine.storage_participant.reply(@engine.storage_participant.first)
+ @dashboard.storage_participant.proceed(@dashboard.storage_participant.first)
wait_for(wfid)
wfid
end
def test_count
- #noisy
-
wfid = run_test_count('cancel', false)
#puts
#logger.log.each { |e| p e }
#puts
assert_equal 1, logger.log.select { |e| e['action'] == 'cancel' }.size
sleep 0.350 # since now dispatch_cancel occurs asynchronously...
- assert_equal 0, @engine.storage_participant.size
+ assert_equal 0, @dashboard.storage_participant.size
end
def test_count_remaining_forget
- #noisy
-
wfid = run_test_count('forget', false)
#assert_equal 1, logger.log.select { |e| e['action'] == 'forget' }.size
- assert_equal 1, @engine.storage_participant.size
- assert_equal 'bravo', @engine.storage_participant.first.participant_name
+ assert_equal 1, @dashboard.storage_participant.size
+ assert_equal 'bravo', @dashboard.storage_participant.first.participant_name
- #@engine.context.storage.get_many('expressions').each { |e| p e['fei'] }
- #puts @engine.context.storage.dump('expressions')
- assert_equal 2, @engine.context.storage.get_many('expressions').size
- assert_not_nil @engine.process(wfid)
+ #@dashboard.context.storage.get_many('expressions').each { |e| p e['fei'] }
+ #puts @dashboard.context.storage.dump('expressions')
+ assert_equal 2, @dashboard.context.storage.get_many('expressions').size
+ assert_not_nil @dashboard.process(wfid)
- @engine.storage_participant.reply(@engine.storage_participant.first)
+ @dashboard.storage_participant.proceed(@dashboard.storage_participant.first)
wait_for(wfid)
- @engine.context.storage.get_many('expressions').each { |e| p e['fei'] }
- assert_equal 0, @engine.context.storage.get_many('expressions').size
+ @dashboard.context.storage.get_many('expressions').each { |e| p e['fei'] }
+ assert_equal 0, @dashboard.context.storage.get_many('expressions').size
end
+ def test_count_negative
+
+ pdef = Ruote.define do
+ concurrence :mt => 'mix', :c => -1 do # all but 1
+ set 'a' => 1
+ set 'b' => 2
+ set 'c' => 3
+ end
+ end
+
+ wfid = @dashboard.launch(pdef)
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal 1, r['workitem']['fields']['a']
+ assert_equal 2, r['workitem']['fields']['b']
+ assert_equal nil, r['workitem']['fields']['c']
+ end
+
def test_cancel
pdef = Ruote.process_definition do
concurrence do
alpha
alpha
end
end
- alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
+ alpha = @dashboard.register_participant :alpha, Ruote::StorageParticipant
- #noisy
+ wfid = @dashboard.launch(pdef)
- wfid = @engine.launch(pdef)
-
wait_for(:alpha)
wait_for(:alpha)
assert_equal 2, alpha.size
- @engine.cancel_process(wfid)
+ @dashboard.cancel_process(wfid)
wait_for(wfid)
- ps = @engine.process(wfid)
+ ps = @dashboard.process(wfid)
assert_nil ps
+ end
+
+ #
+ # 'wait_for' tests
+
+ # 'wait_for => 1' is equivalent to 'count => 1'
+ #
+ def test_wait_for_int
+
+ pdef = Ruote.define do
+ concurrence :wait_for => 1 do
+ sequence do
+ stall
+ echo 'alpha'
+ end
+ echo 'bravo'
+ end
+ echo 'over.'
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ @dashboard.wait_for(wfid)
+
+ assert_equal %w[ bravo over. ], @tracer.to_a
+ end
+
+ def test_wait_for_zero
+
+ pdef = Ruote.define do
+ concurrence :wait_for => 0, :remaining => :forget do
+ sequence do
+ wait '5s'
+ echo 'alpha'
+ end
+ end
+ echo 'over.'
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ @dashboard.wait_for(wfid)
+
+ assert_equal %w[ over. ], @tracer.to_a
+ end
+
+ def test_wait_for_tags
+
+ pdef = Ruote.define do
+ concurrence :wait_for => 'azuma, bashamichi', :merge_type => 'concat' do
+ sequence :tag => 'azuma' do
+ set 'seen' => [ 'azuma' ]
+ end
+ sequence :tag => 'bashamichi' do
+ set 'seen' => [ 'bashamichi' ]
+ end
+ sequence :tag => 'katou' do
+ set 'seen' => [ 'katou' ]
+ end
+ end
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal %w[ azuma bashamichi ], r['workitem']['fields']['seen'].sort
+ end
+
+ def test_wait_for_tags_array
+
+ pdef = Ruote.define do
+ concurrence :wait_for => %w[ azuma bashamichi ], :mt => 'concat' do
+ sequence :tag => 'azuma' do
+ set 'seen' => [ 'azuma' ]
+ end
+ sequence :tag => 'bashamichi' do
+ set 'seen' => [ 'bashamichi' ]
+ end
+ sequence :tag => 'katou' do
+ set 'seen' => [ 'katou' ]
+ wait '5s'
+ end
+ end
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal %w[ azuma bashamichi ], r['workitem']['fields']['seen'].sort
+ end
+
+ def test_wait_for_one_tag
+
+ @dashboard.register do
+ administrator do |workitem|
+ tracer << "administrator\n"
+ sleep 0.7
+ end
+ evaluator Ruote::NullParticipant
+ #evaluator Ruote::NoOpParticipant
+ end
+
+ pdef = Ruote.process_definition do
+ concurrence :wait_for => 'first' do
+ sequence :tag => 'first' do
+ administrator
+ end
+ sequence :tag => 'second' do
+ evaluator
+ end
+ end
+ echo 'done.'
+ end
+
+ wfid = @dashboard.launch(pdef)
+
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal 'terminated', r['action']
+ assert_equal "administrator\ndone.", @tracer.to_s
+ end
+
+ def test_wait_for_unknown_tag
+
+ pdef = Ruote.define do
+ concurrence :wait_for => 'nada' do
+ echo 'a'
+ echo 'b'
+ end
+ echo 'c'
+ end
+
+ wfid = @dashboard.launch(pdef)
+ r = @dashboard.wait_for(wfid)
+
+ assert_equal 'ceased', r['action']
+ assert_equal %w[ a b ], @tracer.to_a.sort
+ end
+
+ def test_remaining_wait
+
+ pdef = Ruote.define do
+ concurrence :count => 1, :rem => 'wait', :mt => 'mix' do
+ set 'a' => true
+ sequence do
+ set 'b' => true
+ stall
+ end
+ end
+ end
+
+ wfid = @dashboard.launch(pdef); r = @dashboard.wait_for(wfid)
+
+ assert_equal(
+ { 'a' => true, 'b' => true, '__result__' => true },
+ r['workitem']['fields'])
end
end