Skip to content

Commit 8215915

Browse files
committed
review fixes, added test
1 parent 1ac7d36 commit 8215915

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ Prerequisites:
2828
* [context_propagation](context_propagation) - Use interceptors to propagate thread/fiber local data from clients
2929
through workflows/activities.
3030
* [message_passing_simple](message_passing_simple) - Simple workflow that accepts signals, queries, and updates.
31+
* [polling/infrequent](polling/infrequent) - Implement an infrequent polling mechanism using Temporal's automatic Activity Retry feature.
3132
* [rails_app](rails_app) - Basic Rails API application using Temporal workflows and activities.
3233
* [sorbet_generic](sorbet_generic) - Proof of concept of how to do _advanced_ Sorbet typing with the SDK.
3334
* [worker_specific_task_queues](worker_specific_task_queues) - Use a unique Task Queue for each Worker to run a sequence of Activities on the same Worker.
34-
* [polling/infrequent](polling/infrequent/) - implement an infrequent polling mechanism using Temporal's automatic Activity Retry feature
3535

3636
## Development
3737

polling/infrequent/greeting_workflow.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require 'temporalio/workflow'
44
require_relative 'compose_greeting_activity'
5-
require_relative 'test_service'
65

76
module Polling
87
module Infrequent
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'test'
4+
require 'securerandom'
5+
require 'temporalio/testing'
6+
require 'temporalio/worker'
7+
require 'polling/infrequent/greeting_workflow'
8+
require 'polling/infrequent/compose_greeting_activity'
9+
require 'polling/infrequent/test_service'
10+
11+
module Polling
12+
class InfrequentPollingTest < Test
13+
def test_workflow_completes_after_polling
14+
task_queue = "tq-#{SecureRandom.uuid}"
15+
16+
Temporalio::Testing::WorkflowEnvironment.start_time_skipping do |env|
17+
worker = Temporalio::Worker.new(
18+
client: env.client,
19+
task_queue: task_queue,
20+
activities: [Polling::Infrequent::ComposeGreetingActivity],
21+
workflows: [Polling::Infrequent::GreetingWorkflow]
22+
)
23+
24+
handle = env.client.start_workflow(
25+
Polling::Infrequent::GreetingWorkflow,
26+
'Temporal',
27+
id: "wf-#{SecureRandom.uuid}",
28+
task_queue: task_queue
29+
)
30+
31+
worker.run do
32+
# Advance time forward to allow for the 4 retries (4 * 60s) plus a buffer
33+
env.sleep(241)
34+
35+
# Wait for the workflow to complete and assert its result
36+
result = handle.result
37+
assert_equal('Hello, Temporal!', result)
38+
end
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)