From 444222dc5a50ed102670ccd1f4c64d05d8804160 Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Thu, 9 Oct 2025 12:07:49 -0700 Subject: [PATCH 1/4] Add basic test for eager workflow start sample --- test/eager_wf_start/eager_workflow_test.rb | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/eager_wf_start/eager_workflow_test.rb diff --git a/test/eager_wf_start/eager_workflow_test.rb b/test/eager_wf_start/eager_workflow_test.rb new file mode 100644 index 0000000..d5e37fb --- /dev/null +++ b/test/eager_wf_start/eager_workflow_test.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'test' +require 'eager_wf_start/eager_workflow' +require 'securerandom' +require 'temporalio/testing' +require 'temporalio/worker' + +module EagerWfStart + class EagerWorkflowTest < Test + def test_workflow + # Run test server until completion of the block + Temporalio::Testing::WorkflowEnvironment.start_local do |env| + # Run worker until completion of the block + worker = Temporalio::Worker.new( + client: env.client, + task_queue: "tq-#{SecureRandom.uuid}", + activities: [GreetingActivity], + workflows: [EagerWorkflow] + ) + worker.run do + # Run workflow with eager start + result = env.client.execute_workflow( + EagerWorkflow, + 'Temporal', + id: "wf-#{SecureRandom.uuid}", + task_queue: worker.task_queue, + request_eager_start: true + ) + assert_equal('Hello, Temporal!', result) + end + end + end + end +end From c55412b73ae219fa5bda83426450870a788b1c05 Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Thu, 9 Oct 2025 13:43:15 -0700 Subject: [PATCH 2/4] Address minor suggestions --- README.md | 2 +- {eager_wf_start => eager_workflow_start}/README.md | 2 +- {eager_wf_start => eager_workflow_start}/eager_workflow.rb | 0 {eager_wf_start => eager_workflow_start}/greeting_activity.rb | 0 {eager_wf_start => eager_workflow_start}/run.rb | 4 ++-- .../eager_workflow_test.rb | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename {eager_wf_start => eager_workflow_start}/README.md (94%) rename {eager_wf_start => eager_workflow_start}/eager_workflow.rb (100%) rename {eager_wf_start => eager_workflow_start}/greeting_activity.rb (100%) rename {eager_wf_start => eager_workflow_start}/run.rb (89%) rename test/{eager_wf_start => eager_workflow_start}/eager_workflow_test.rb (95%) diff --git a/README.md b/README.md index 783abce..973b838 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Prerequisites: * [context_propagation](context_propagation) - Use interceptors to propagate thread/fiber local data from clients through workflows/activities. * [dsl](dsl) - Demonstrates having a workflow interpret/invoke arbitrary steps defined in a DSL. -* [eager_wf_start](eager_wf_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity. +* [eager_workflow_start](eager_workflow_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity. * [encryption](encryption) - Demonstrates how to make a codec for end-to-end encryption. * [env_config](env_config) - Load client configuration from TOML files with programmatic overrides. * [message_passing_simple](message_passing_simple) - Simple workflow that accepts signals, queries, and updates. diff --git a/eager_wf_start/README.md b/eager_workflow_start/README.md similarity index 94% rename from eager_wf_start/README.md rename to eager_workflow_start/README.md index 8603375..fa983d9 100644 --- a/eager_wf_start/README.md +++ b/eager_workflow_start/README.md @@ -11,4 +11,4 @@ You can read more about Eager Workflow Start in our: To run, first see [README.md](../README.md) for prerequisites. Then run the sample via: - bundle exec ruby eager_wf_start/run.rb + bundle exec ruby eager_workflow_start/run.rb diff --git a/eager_wf_start/eager_workflow.rb b/eager_workflow_start/eager_workflow.rb similarity index 100% rename from eager_wf_start/eager_workflow.rb rename to eager_workflow_start/eager_workflow.rb diff --git a/eager_wf_start/greeting_activity.rb b/eager_workflow_start/greeting_activity.rb similarity index 100% rename from eager_wf_start/greeting_activity.rb rename to eager_workflow_start/greeting_activity.rb diff --git a/eager_wf_start/run.rb b/eager_workflow_start/run.rb similarity index 89% rename from eager_wf_start/run.rb rename to eager_workflow_start/run.rb index 76b46d5..0eb1b4e 100644 --- a/eager_wf_start/run.rb +++ b/eager_workflow_start/run.rb @@ -6,7 +6,7 @@ require_relative 'eager_workflow' require_relative 'greeting_activity' -TASK_QUEUE = 'eager-wf-start-task-queue' +TASK_QUEUE = 'eager-wf-start-sample' # Note that the worker and client run in the same process and share the same client connection client = Temporalio::Client.connect('localhost:7233', 'default') @@ -23,7 +23,7 @@ handle = client.start_workflow( EagerWfStart::EagerWorkflow, 'Temporal', - id: "eager-workflow-id-#{SecureRandom.uuid}", + id: 'eager-workflow-start-sample-workflow-id', task_queue: TASK_QUEUE, request_eager_start: true ) diff --git a/test/eager_wf_start/eager_workflow_test.rb b/test/eager_workflow_start/eager_workflow_test.rb similarity index 95% rename from test/eager_wf_start/eager_workflow_test.rb rename to test/eager_workflow_start/eager_workflow_test.rb index d5e37fb..c55a7b6 100644 --- a/test/eager_wf_start/eager_workflow_test.rb +++ b/test/eager_workflow_start/eager_workflow_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'test' -require 'eager_wf_start/eager_workflow' +require 'eager_workflow_start/eager_workflow' require 'securerandom' require 'temporalio/testing' require 'temporalio/worker' From 7fb84917fc0ed494d99baaee71804c1156ad116b Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Thu, 9 Oct 2025 23:03:16 -0700 Subject: [PATCH 3/4] small fixes --- eager_workflow_start/README.md | 2 +- eager_workflow_start/eager_workflow.rb | 2 +- eager_workflow_start/greeting_activity.rb | 2 +- eager_workflow_start/run.rb | 8 ++++---- test/eager_workflow_start/eager_workflow_test.rb | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eager_workflow_start/README.md b/eager_workflow_start/README.md index fa983d9..077e639 100644 --- a/eager_workflow_start/README.md +++ b/eager_workflow_start/README.md @@ -11,4 +11,4 @@ You can read more about Eager Workflow Start in our: To run, first see [README.md](../README.md) for prerequisites. Then run the sample via: - bundle exec ruby eager_workflow_start/run.rb + bundle exec ruby run.rb diff --git a/eager_workflow_start/eager_workflow.rb b/eager_workflow_start/eager_workflow.rb index 8b64134..def7861 100644 --- a/eager_workflow_start/eager_workflow.rb +++ b/eager_workflow_start/eager_workflow.rb @@ -3,7 +3,7 @@ require 'temporalio/workflow' require_relative 'greeting_activity' -module EagerWfStart +module EagerWorkflowStart class EagerWorkflow < Temporalio::Workflow::Definition def execute(name) Temporalio::Workflow.execute_local_activity( diff --git a/eager_workflow_start/greeting_activity.rb b/eager_workflow_start/greeting_activity.rb index 1d61bce..9b312c8 100644 --- a/eager_workflow_start/greeting_activity.rb +++ b/eager_workflow_start/greeting_activity.rb @@ -2,7 +2,7 @@ require 'temporalio/activity' -module EagerWfStart +module EagerWorkflowStart class GreetingActivity < Temporalio::Activity::Definition def execute(name) "Hello, #{name}!" diff --git a/eager_workflow_start/run.rb b/eager_workflow_start/run.rb index 0eb1b4e..677040f 100644 --- a/eager_workflow_start/run.rb +++ b/eager_workflow_start/run.rb @@ -6,7 +6,7 @@ require_relative 'eager_workflow' require_relative 'greeting_activity' -TASK_QUEUE = 'eager-wf-start-sample' +TASK_QUEUE = 'eager-workflow-start-sample' # Note that the worker and client run in the same process and share the same client connection client = Temporalio::Client.connect('localhost:7233', 'default') @@ -14,14 +14,14 @@ worker = Temporalio::Worker.new( client:, task_queue: TASK_QUEUE, - workflows: [EagerWfStart::EagerWorkflow], - activities: [EagerWfStart::GreetingActivity] + workflows: [EagerWorkflowStart::EagerWorkflow], + activities: [EagerWorkflowStart::GreetingActivity] ) # Run worker in the background while we start the workflow worker.run do handle = client.start_workflow( - EagerWfStart::EagerWorkflow, + EagerWorkflowStart::EagerWorkflow, 'Temporal', id: 'eager-workflow-start-sample-workflow-id', task_queue: TASK_QUEUE, diff --git a/test/eager_workflow_start/eager_workflow_test.rb b/test/eager_workflow_start/eager_workflow_test.rb index c55a7b6..0f924a4 100644 --- a/test/eager_workflow_start/eager_workflow_test.rb +++ b/test/eager_workflow_start/eager_workflow_test.rb @@ -6,7 +6,7 @@ require 'temporalio/testing' require 'temporalio/worker' -module EagerWfStart +module EagerWorkflowStart class EagerWorkflowTest < Test def test_workflow # Run test server until completion of the block From 27bcdc0cf74098aa6b3ef89ea4d890f734c7cd30 Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Fri, 10 Oct 2025 12:41:30 -0700 Subject: [PATCH 4/4] Add eager started assertion to test --- test/eager_workflow_start/eager_workflow_test.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/eager_workflow_start/eager_workflow_test.rb b/test/eager_workflow_start/eager_workflow_test.rb index 0f924a4..9461ee4 100644 --- a/test/eager_workflow_start/eager_workflow_test.rb +++ b/test/eager_workflow_start/eager_workflow_test.rb @@ -10,7 +10,9 @@ module EagerWorkflowStart class EagerWorkflowTest < Test def test_workflow # Run test server until completion of the block - Temporalio::Testing::WorkflowEnvironment.start_local do |env| + Temporalio::Testing::WorkflowEnvironment.start_local( + dev_server_download_version: 'latest' + ) do |env| # Run worker until completion of the block worker = Temporalio::Worker.new( client: env.client, @@ -19,15 +21,19 @@ def test_workflow workflows: [EagerWorkflow] ) worker.run do - # Run workflow with eager start - result = env.client.execute_workflow( + # Start workflow with eager start + handle = env.client.start_workflow( EagerWorkflow, 'Temporal', id: "wf-#{SecureRandom.uuid}", task_queue: worker.task_queue, request_eager_start: true ) - assert_equal('Hello, Temporal!', result) + assert_equal('Hello, Temporal!', handle.result) + + # Verify workflow was eagerly executed + started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes) + assert(started_event.workflow_execution_started_event_attributes.eager_execution_accepted) end end end