Skip to content
Merged
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
10 changes: 4 additions & 6 deletions temporalio/lib/temporalio/workflow/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def self.method_added(method_name)
@workflow_update_validators ||= {}
@defined_methods ||= []

defn, hash, other_hashes =
defn, hash =
case handler[:type]
when :init
raise "workflow_init was applied to #{method_name} instead of initialize" if method_name != :initialize
Expand All @@ -306,7 +306,7 @@ def self.method_added(method_name)
raw_args: handler[:raw_args],
unfinished_policy: handler[:unfinished_policy],
arg_hints: handler[:arg_hints]
), @workflow_signals, [@workflow_queries, @workflow_updates]]
), @workflow_signals]
when :query
[Query.new(
name: handler[:dynamic] ? nil : (handler[:name] || method_name).to_s,
Expand All @@ -315,7 +315,7 @@ def self.method_added(method_name)
raw_args: handler[:raw_args],
arg_hints: handler[:arg_hints],
result_hint: handler[:result_hint]
), @workflow_queries, [@workflow_signals, @workflow_updates]]
), @workflow_queries]
when :update
[Update.new(
name: handler[:dynamic] ? nil : (handler[:name] || method_name).to_s,
Expand All @@ -325,7 +325,7 @@ def self.method_added(method_name)
unfinished_policy: handler[:unfinished_policy],
arg_hints: handler[:arg_hints],
result_hint: handler[:result_hint]
), @workflow_updates, [@workflow_signals, @workflow_queries]]
), @workflow_updates]
when :dynamic_options
raise 'Dynamic options method already set' if @dynamic_options_method

Expand All @@ -341,8 +341,6 @@ def self.method_added(method_name)
if other && other.to_invoke != method_name
raise "Workflow #{handler[:type].name} #{defn.name || '<dynamic>'} defined on " \
"different methods #{other.to_invoke} and #{method_name}"
elsif defn.name && other_hashes.any? { |h| h.include?(defn.name) }
raise "Workflow signal #{defn.name} already defined as a different handler type"
end
hash[defn.name] = defn

Expand Down
30 changes: 30 additions & 0 deletions temporalio/test/worker_workflow_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -946,4 +946,34 @@ def test_signal_with_start_user_metadata
assert_equal 'my-details', desc.static_details
end
end

class HandlerNameReuseWorkflow < Temporalio::Workflow::Definition
def execute
Temporalio::Workflow.wait_condition { @signal }
end

workflow_signal name: :foo
def foo_signal(value)
@signal = value
end

workflow_query name: :foo
def foo_query
'query-done'
end

workflow_update name: :foo
def foo_update
'update-done'
end
end

def test_handler_name_reuse
execute_workflow(HandlerNameReuseWorkflow) do |handle|
assert_equal 'query-done', handle.query(HandlerNameReuseWorkflow.foo_query)
assert_equal 'update-done', handle.execute_update(HandlerNameReuseWorkflow.foo_update)
handle.signal(HandlerNameReuseWorkflow.foo_signal, 'signal-done')
assert_equal 'signal-done', handle.result
end
end
end
12 changes: 0 additions & 12 deletions temporalio/test/workflow/definition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,6 @@ def my_signal_2; end
CODE
end

def test_invalid_duplicate_handlers_different_type
assert_invalid_workflow_code 'my-name already defined as a different handler type', <<~CODE
class TestInvalidDuplicateHandlersDifferentType < Temporalio::Workflow::Definition
workflow_signal name: 'my-name'
def my_signal; end

workflow_update name: 'my-name'
def my_update; end
end
CODE
end

def test_invalid_init_not_on_initialize
assert_invalid_workflow_code 'was applied to not_initialize instead of initialize', <<~CODE
class TestInvalidInitNotOnInitialize < Temporalio::Workflow::Definition
Expand Down
Loading