Skip to content

Commit 689d332

Browse files
authored
Add basic test for eager workflow start sample (#57)
* Add basic test for eager workflow start sample * Address minor suggestions * small fixes * Add eager started assertion to test
1 parent 2c75cee commit 689d332

6 files changed

Lines changed: 50 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Prerequisites:
2323
* [context_propagation](context_propagation) - Use interceptors to propagate thread/fiber local data from clients
2424
through workflows/activities.
2525
* [dsl](dsl) - Demonstrates having a workflow interpret/invoke arbitrary steps defined in a DSL.
26-
* [eager_wf_start](eager_wf_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity.
26+
* [eager_workflow_start](eager_workflow_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity.
2727
* [encryption](encryption) - Demonstrates how to make a codec for end-to-end encryption.
2828
* [env_config](env_config) - Load client configuration from TOML files with programmatic overrides.
2929
* [message_passing_simple](message_passing_simple) - Simple workflow that accepts signals, queries, and updates.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ You can read more about Eager Workflow Start in our:
1111

1212
To run, first see [README.md](../README.md) for prerequisites. Then run the sample via:
1313

14-
bundle exec ruby eager_wf_start/run.rb
14+
bundle exec ruby run.rb
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'temporalio/workflow'
44
require_relative 'greeting_activity'
55

6-
module EagerWfStart
6+
module EagerWorkflowStart
77
class EagerWorkflow < Temporalio::Workflow::Definition
88
def execute(name)
99
Temporalio::Workflow.execute_local_activity(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'temporalio/activity'
44

5-
module EagerWfStart
5+
module EagerWorkflowStart
66
class GreetingActivity < Temporalio::Activity::Definition
77
def execute(name)
88
"Hello, #{name}!"
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
require_relative 'eager_workflow'
77
require_relative 'greeting_activity'
88

9-
TASK_QUEUE = 'eager-wf-start-task-queue'
9+
TASK_QUEUE = 'eager-workflow-start-sample'
1010

1111
# Note that the worker and client run in the same process and share the same client connection
1212
client = Temporalio::Client.connect('localhost:7233', 'default')
1313

1414
worker = Temporalio::Worker.new(
1515
client:,
1616
task_queue: TASK_QUEUE,
17-
workflows: [EagerWfStart::EagerWorkflow],
18-
activities: [EagerWfStart::GreetingActivity]
17+
workflows: [EagerWorkflowStart::EagerWorkflow],
18+
activities: [EagerWorkflowStart::GreetingActivity]
1919
)
2020

2121
# Run worker in the background while we start the workflow
2222
worker.run do
2323
handle = client.start_workflow(
24-
EagerWfStart::EagerWorkflow,
24+
EagerWorkflowStart::EagerWorkflow,
2525
'Temporal',
26-
id: "eager-workflow-id-#{SecureRandom.uuid}",
26+
id: 'eager-workflow-start-sample-workflow-id',
2727
task_queue: TASK_QUEUE,
2828
request_eager_start: true
2929
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
require 'test'
4+
require 'eager_workflow_start/eager_workflow'
5+
require 'securerandom'
6+
require 'temporalio/testing'
7+
require 'temporalio/worker'
8+
9+
module EagerWorkflowStart
10+
class EagerWorkflowTest < Test
11+
def test_workflow
12+
# Run test server until completion of the block
13+
Temporalio::Testing::WorkflowEnvironment.start_local(
14+
dev_server_download_version: 'latest'
15+
) do |env|
16+
# Run worker until completion of the block
17+
worker = Temporalio::Worker.new(
18+
client: env.client,
19+
task_queue: "tq-#{SecureRandom.uuid}",
20+
activities: [GreetingActivity],
21+
workflows: [EagerWorkflow]
22+
)
23+
worker.run do
24+
# Start workflow with eager start
25+
handle = env.client.start_workflow(
26+
EagerWorkflow,
27+
'Temporal',
28+
id: "wf-#{SecureRandom.uuid}",
29+
task_queue: worker.task_queue,
30+
request_eager_start: true
31+
)
32+
assert_equal('Hello, Temporal!', handle.result)
33+
34+
# Verify workflow was eagerly executed
35+
started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes)
36+
assert(started_event.workflow_execution_started_event_attributes.eager_execution_accepted)
37+
end
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)