diff --git a/examples/activities/hello_world_activity.rb b/examples/activities/hello_world_activity.rb index 9fcd3d91..a957c310 100644 --- a/examples/activities/hello_world_activity.rb +++ b/examples/activities/hello_world_activity.rb @@ -1,5 +1,7 @@ class HelloWorldActivity < Cadence::Activity def execute(name) + raise 'Test error' if name == 'Failure' + p "Hello World, #{name}" return diff --git a/examples/spec/integration/parent_workflow_spec.rb b/examples/spec/integration/parent_workflow_spec.rb index d87c7ea6..df5993e5 100644 --- a/examples/spec/integration/parent_workflow_spec.rb +++ b/examples/spec/integration/parent_workflow_spec.rb @@ -1,3 +1,4 @@ +require 'securerandom' require 'workflows/parent_workflow' describe ParentWorkflow do @@ -14,13 +15,34 @@ expect(HelloWorldWorkflow).to have_received(:execute!) end - it 'executes HelloWorldActivity' do + it 'executes HelloWorldActivity twice' do subject.execute_locally - expect(HelloWorldActivity).to have_received(:execute!).with('Bob') + expect(HelloWorldActivity).to have_received(:execute!).with('Alice').ordered + expect(HelloWorldActivity).to have_received(:execute!).with('Bob').ordered end it 'returns nil' do expect(subject.execute_locally).to eq(nil) end + + context 'integration' do + let(:workflow_id) { SecureRandom.uuid } + + around do |example| + Cadence::Testing.local! do + example.run + end + end + + it 'works' do + run_id = Cadence.start_workflow(described_class, options: { workflow_id: workflow_id }) + info = Cadence.fetch_workflow_execution_info('test', workflow_id, run_id) + + expect(HelloWorldActivity).to have_received(:execute!).with('Failure').ordered + expect(HelloWorldActivity).to have_received(:execute!).with('Rescue').ordered + + expect(info).to be_completed + end + end end diff --git a/examples/workflows/hello_world_workflow.rb b/examples/workflows/hello_world_workflow.rb index 31021dd8..92f51a09 100644 --- a/examples/workflows/hello_world_workflow.rb +++ b/examples/workflows/hello_world_workflow.rb @@ -2,7 +2,7 @@ class HelloWorldWorkflow < Cadence::Workflow def execute - HelloWorldActivity.execute!('Alice') + HelloWorldActivity.execute!('Failure') return end diff --git a/examples/workflows/parent_workflow.rb b/examples/workflows/parent_workflow.rb index 68d4e95d..7c44f174 100644 --- a/examples/workflows/parent_workflow.rb +++ b/examples/workflows/parent_workflow.rb @@ -7,5 +7,7 @@ def execute HelloWorldActivity.execute!('Bob') return + rescue + HelloWorldActivity.execute!('Rescue') end end diff --git a/lib/cadence/workflow.rb b/lib/cadence/workflow.rb index c718b03c..37da0fcf 100644 --- a/lib/cadence/workflow.rb +++ b/lib/cadence/workflow.rb @@ -9,6 +9,7 @@ class Workflow extend ConvenienceMethods def self.execute_in_context(context, input) + previous_context = Cadence::ThreadLocalContext.get Cadence::ThreadLocalContext.set(context) workflow = new(context) @@ -22,6 +23,8 @@ def self.execute_in_context(context, input) Cadence::ErrorHandler.handle(error, metadata: context.metadata) context.fail(error.class.name, error.message) + ensure + Cadence::ThreadLocalContext.set(previous_context) if previous_context end def initialize(context)