Skip to content

[WIP] Spec for a child workflow #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/activities/hello_world_activity.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class HelloWorldActivity < Cadence::Activity
def execute(name)
raise 'Test error' if name == 'Failure'

p "Hello World, #{name}"

return
Expand Down
26 changes: 24 additions & 2 deletions examples/spec/integration/parent_workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -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('Failure').ordered
expect(HelloWorldActivity).to have_received(:execute!).with('Rescue').ordered

expect(info).to be_completed
end
end
end
2 changes: 1 addition & 1 deletion examples/workflows/hello_world_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HelloWorldWorkflow < Cadence::Workflow
def execute
HelloWorldActivity.execute!('Alice')
HelloWorldActivity.execute!('Failure')

return
end
Expand Down
2 changes: 2 additions & 0 deletions examples/workflows/parent_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ def execute
HelloWorldActivity.execute!('Bob')

return
rescue
HelloWorldActivity.execute!('Rescue')
end
end
3 changes: 3 additions & 0 deletions lib/cadence/workflow.rb
Original file line number Diff line number Diff line change
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