Skip to content

Commit

Permalink
[WIP] Spec for a child workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonydmitriyev committed Sep 22, 2021
1 parent 1fb2765 commit 76e1ade
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
26 changes: 24 additions & 2 deletions examples/spec/integration/parent_workflow_spec.rb
@@ -1,3 +1,4 @@
require 'securerandom'
require 'workflows/parent_workflow'

describe ParentWorkflow do
Expand All @@ -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('Alice').ordered
expect(HelloWorldActivity).to have_received(:execute!).with('Bob').ordered

expect(info).to be_completed
end
end
end
3 changes: 3 additions & 0 deletions lib/cadence/workflow.rb
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 76e1ade

Please sign in to comment.