test/functional/ft_25_receiver.rb in ruote-2.1.9 vs test/functional/ft_25_receiver.rb in ruote-2.1.10
- old
+ new
@@ -47,16 +47,43 @@
true
end
end
class MyReceiver < Ruote::Receiver
+ attr_reader :context
end
- def test_my_receiver
+ def test_my_receiver_init
+ cid = @engine.context.object_id
+
+ receiver = MyReceiver.new(@engine)
+ assert_equal cid, receiver.context.object_id
+ assert_not_nil receiver.context.storage
+
+ receiver = MyReceiver.new(@engine.context)
+ assert_equal cid, receiver.context.object_id
+ assert_not_nil receiver.context.storage
+
+ receiver = MyReceiver.new(@engine.worker)
+ assert_equal cid, receiver.context.object_id
+ assert_not_nil receiver.context.storage
+
receiver = MyReceiver.new(@engine.storage)
+ assert_equal cid, receiver.context.object_id
+ assert_not_nil receiver.context.storage
+ @engine.storage.instance_variable_set(:@context, nil)
+ receiver = MyReceiver.new(@engine.storage)
+ assert_not_equal cid, receiver.context.object_id
+ assert_not_nil receiver.context.storage
+ end
+
+ def test_my_receiver
+
+ receiver = MyReceiver.new(@engine.context)
+
#noisy
wfid = @engine.launch(@pdef)
wait_for(:alpha)
@@ -88,8 +115,63 @@
assert_nil @engine.process(wfid)
rcv = logger.log.select { |e| e['action'] == 'receive' }.first
assert_equal 'Ruote::Engine', rcv['receiver']
+ end
+
+ class MyOtherParticipant
+ def initialize (receiver)
+ @receiver = receiver
+ end
+ def consume (workitem)
+ @receiver.pass(workitem.to_h)
+ end
+ end
+ class MyOtherReceiver < Ruote::Receiver
+ def initialize (context, opts={})
+ super(context, opts)
+ @count = 0
+ end
+ def pass (workitem)
+ if @count < 1
+ @context.error_handler.action_handle(
+ 'dispatch', workitem['fei'], RuntimeError.new('something went wrong'))
+ else
+ reply(workitem)
+ end
+ @count = @count + 1
+ end
+ end
+
+ def test_receiver_triggered_dispatch_error
+
+ receiver = MyOtherReceiver.new(@engine)
+
+ @engine.register_participant :alpha, MyOtherParticipant.new(receiver)
+
+ pdef = Ruote.process_definition do
+ alpha
+ end
+
+ #noisy
+
+ wfid = @engine.launch(pdef)
+
+ wait_for(wfid)
+
+ ps = @engine.process(wfid)
+ err = ps.errors.first
+
+ assert_equal 1, ps.errors.size
+ assert_equal '#<RuntimeError: something went wrong>', err.message
+
+ @engine.replay_at_error(err)
+
+ wait_for(wfid)
+
+ ps = @engine.process(wfid)
+
+ assert_nil ps
end
end