test/functional/ft_2_errors.rb in ruote-2.2.0 vs test/functional/ft_2_errors.rb in ruote-2.3.0

- old
+ new

@@ -3,11 +3,11 @@ # testing ruote # # Fri May 15 09:51:28 JST 2009 # -require File.join(File.dirname(__FILE__), 'base') +require File.expand_path('../base', __FILE__) require 'ruote/participant' class FtErrorsTest < Test::Unit::TestCase @@ -17,18 +17,18 @@ pdef = Ruote.process_definition do nada end - wfid = @engine.launch(pdef) - wait_for(wfid) + wfid = @dashboard.launch(pdef) + @dashboard.wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 1, ps.errors.size - pss = @engine.processes + pss = @dashboard.processes assert_equal 1, pss.size assert_equal 1, pss.first.errors.size end @@ -38,52 +38,48 @@ pdef = Ruote.process_definition do nada end - #noisy - - wfid = @engine.launch(pdef) + wfid = @dashboard.launch(pdef) wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) exp = ps.expressions.find { |fe| fe.class == Ruote::Exp::RefExpression } assert_not_nil exp - @engine.register_participant :nada do |workitem| - @tracer << 'done.' + @dashboard.register_participant :nada do |workitem| + tracer << 'done.' end - @engine.re_apply(exp.fei) + @dashboard.re_apply(exp.fei) wait_for(wfid) assert_equal 'done.', @tracer.to_s - assert_equal 0, @engine.storage.get_many('errors').size + assert_equal 0, @dashboard.storage.get_many('errors').size end def test_error_replay pdef = Ruote.process_definition do nada end - #noisy - - wfid = @engine.launch(pdef) + wfid = @dashboard.launch(pdef) wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) err = ps.errors.first - @engine.replay_at_error(err) + @dashboard.replay_at_error(err) wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) #p ps assert_equal 1, ps.errors.size # only one error @@ -91,43 +87,41 @@ err1 = ps.errors.first assert_not_equal err.at, err1.at # not the same error - assert_equal 1, @engine.storage.get_many('errors').size + assert_equal 1, @dashboard.storage.get_many('errors').size end def test_error_fix_then_replay pdef = Ruote.process_definition do nada end - @engine.register_participant :alpha do - @tracer << "alpha\n" + @dashboard.register_participant :alpha do + tracer << "alpha\n" end - #noisy - - wfid = @engine.launch(pdef) + wfid = @dashboard.launch(pdef) wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) err = ps.errors.first assert_equal [ 'nada', { 'ref' => 'nada' }, [] ], err.tree err.tree = [ 'alpha', {}, [] ] - @engine.replay_at_error(err) + @dashboard.replay_at_error(err) wait_for(wfid) - assert_nil @engine.process(wfid) + assert_nil @dashboard.process(wfid) assert_equal 'alpha', @tracer.to_s # check if error is really gone from error journal... - assert_equal [], @engine.storage.get_many('errors') + assert_equal [], @dashboard.storage.get_many('errors') end def test_error_in_participant pdef = Ruote.process_definition do @@ -135,31 +129,29 @@ alpha echo 'done.' end end - @engine.context.stash[:count] = 0 + @dashboard.context.stash[:count] = 0 - @engine.register_participant :alpha do + @dashboard.register_participant :alpha do stash[:count] += 1 - @tracer << "alpha\n" + tracer << "alpha\n" raise "something went wrong" if stash[:count] == 1 end - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(wfid) sleep 0.250 # grrr... - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 1, ps.errors.size - @engine.replay_at_error(ps.errors.first) + @dashboard.replay_at_error(ps.errors.first) wait_for(wfid) assert_equal %w[ alpha alpha done. ].join("\n"), @tracer.to_s end @@ -171,29 +163,27 @@ alpha echo 'done.' end end - @engine.context.stash[:count] = 0 + @dashboard.context.stash[:count] = 0 - alpha = @engine.register_participant :alpha, 'do_not_thread' => true do + alpha = @dashboard.register_participant :alpha, 'do_not_thread' => true do stash[:count] += 1 - @tracer << "alpha\n" + tracer << "alpha\n" raise "something went wrong" if stash[:count] == 1 end - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 1, ps.errors.size - @engine.replay_at_error(ps.errors.first) + @dashboard.replay_at_error(ps.errors.first) wait_for(wfid) assert_equal %w[ alpha alpha done. ].join("\n"), @tracer.to_s end @@ -218,33 +208,31 @@ pdef = Ruote.process_definition do alpha end - @engine.register_participant 'alpha', WeakCancelParticipant + @dashboard.register_participant 'alpha', WeakCancelParticipant - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(:alpha) - @engine.cancel_process(wfid) + @dashboard.cancel_process(wfid) wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) #puts ps.errors.first.trace assert_equal 1, ps.errors.size assert_equal 2, ps.expressions.size - @engine.kill_process(wfid) + @dashboard.kill_process(wfid) wait_for(wfid) - assert_nil @engine.process(wfid) + assert_nil @dashboard.process(wfid) end def test_errors_and_subprocesses pdef = Ruote.process_definition do @@ -255,34 +243,32 @@ define 'sub0' do alpha end end - @engine.context.stash[:count] = 0 + @dashboard.context.stash[:count] = 0 - alpha = @engine.register_participant :alpha, :do_not_thread => true do + alpha = @dashboard.register_participant :alpha, :do_not_thread => true do stash[:count] += 1 - @tracer << "alpha\n" + tracer << "alpha\n" raise "something went wrong" if stash[:count] == 1 end - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(wfid) - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 1, ps.errors.size err = ps.errors.first assert_equal wfid, err.fei.wfid assert_not_nil err.fei.subid - @engine.replay_at_error(err) + @dashboard.replay_at_error(err) wait_for(wfid) assert_equal %w[ alpha alpha done. ].join("\n"), @tracer.to_s end @@ -291,24 +277,22 @@ pdef = Ruote.process_definition do nada end - #noisy + wfid = @dashboard.launch(pdef) - wfid = @engine.launch(pdef) - wait_for(wfid) - assert_equal 1, @engine.process(wfid).errors.size + assert_equal 1, @dashboard.process(wfid).errors.size - @engine.cancel_process(wfid) + @dashboard.cancel_process(wfid) wait_for(wfid) - assert_nil @engine.process(wfid) - assert_equal [], @engine.storage.get_many('errors') + assert_nil @dashboard.process(wfid) + assert_equal [], @dashboard.storage.get_many('errors') end def test_forgotten_subprocess pdef = Ruote.process_definition do @@ -319,37 +303,85 @@ define 'sub0' do error 'broken wing' end end - wfid = @engine.launch(pdef) + wfid = @dashboard.launch(pdef) wait_for(wfid) wait_for(wfid) assert_equal 'done.', @tracer.to_s - ps = @engine.process(wfid) + ps = @dashboard.process(wfid) assert_equal 3, ps.expressions.size assert_equal 1, ps.errors.size - @engine.replay_at_error(ps.errors.first) + @dashboard.replay_at_error(ps.errors.first) wait_for(wfid) - assert_nil @engine.process(wfid) + assert_nil @dashboard.process(wfid) end def test_error_intercepted pdef = Ruote.process_definition do nada end - wfid = @engine.launch(pdef) + wfid = @dashboard.launch(pdef) - r = @engine.wait_for(wfid) + r = @dashboard.wait_for(wfid) + assert_equal 'error_intercepted', r['action'] assert_equal 'RuntimeError', r['error']['class'] assert_equal "unknown participant or subprocess 'nada'", r['error']['message'] assert_equal Array, r['error']['trace'].class + assert_equal [ 'nada', { 'ref' => 'nada' }, [] ], r['error']['tree'] + end + + def test_replay_at_error_fei + + @dashboard.register { catchall } + + wfid = @dashboard.launch(Ruote.define do + error 'alpha' + error 'bravo' + end) + + @dashboard.wait_for(wfid) + + err = @dashboard.ps(wfid).errors.first + assert_match /alpha/, err.message + fei = err.fei + + @dashboard.replay_at_error(fei) + + @dashboard.wait_for(wfid) + + err = @dashboard.ps(wfid).errors.first + assert_match /bravo/, err.message + end + + class MyError < RuntimeError + def ruote_details + 'where the devil is' + end + end + + def test_error_details + + @dashboard.register :alpha do |workitem| + raise FtErrorsTest::MyError + end + + wfid = @dashboard.launch(Ruote.define do + alpha + end) + + @dashboard.wait_for('error_intercepted') + + assert_equal 'where the devil is', @dashboard.ps(wfid).errors.first.details + + #p @dashboard.ps(wfid) end end