Skip to content

Commit

Permalink
Cleanup spec fabricators from explicit references to Temporal.configu…
Browse files Browse the repository at this point in the history
…ration.converter
  • Loading branch information
antstorm committed Mar 3, 2022
1 parent 2780328 commit 195fa49
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 28 deletions.
4 changes: 1 addition & 3 deletions examples/spec/integration/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
completion_event = events[:EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED].first
result = completion_event.workflow_execution_completed_event_attributes.result

converter = Temporal.configuration.converter

expect(converter.from_payloads(result)&.first).to eq('Hello World, Tom')
expect($converter.from_payloads(result)&.first).to eq('Hello World, Tom')
end
end
7 changes: 6 additions & 1 deletion spec/config/temporal.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require 'temporal/converter_wrapper'
require 'temporal/configuration'

$converter = Temporal::ConverterWrapper.new(Temporal::Configuration::DEFAULT_CONVERTER)

RSpec.configure do |config|
config.before(:each) do
Temporal.configuration.error_handlers.clear
end
end
end
7 changes: 2 additions & 5 deletions spec/fabricators/grpc/activity_task_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
activity_id { SecureRandom.uuid }
task_token { |attrs| attrs[:task_token] || SecureRandom.uuid }
activity_type { Fabricate(:api_activity_type) }
input { Temporal.configuration.converter.to_payloads(nil) }
input { $converter.to_payloads(nil) }
workflow_type { Fabricate(:api_workflow_type) }
workflow_execution { Fabricate(:api_workflow_execution) }
current_attempt_scheduled_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
started_time { Google::Protobuf::Timestamp.new.tap { |t| t.from_time(Time.now) } }
header do |attrs|
fields = (attrs[:headers] || {}).each_with_object({}) do |(field, value), h|
h[field] = Temporal.configuration.converter.to_payload(value)
end
Temporal::Api::Common::V1::Header.new(fields: fields)
Temporal::Api::Common::V1::Header.new(fields: $converter.to_payload_map(attrs[:headers] || {}))
end
end
4 changes: 1 addition & 3 deletions spec/fabricators/grpc/application_failure_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'temporal/configuration'

# Simulates Temporal::Connection::Serializer::Failure
Fabricator(:api_application_failure, from: Temporal::Api::Failure::V1::Failure) do
transient :error_class, :backtrace
Expand All @@ -8,7 +6,7 @@
application_failure_info do |attrs|
Temporal::Api::Failure::V1::ApplicationFailureInfo.new(
type: attrs[:error_class],
details: Temporal::Configuration.new.converter.to_details_payloads(attrs[:message]),
details: $converter.to_details_payloads(attrs[:message]),
)
end
end
8 changes: 3 additions & 5 deletions spec/fabricators/grpc/history_event_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'securerandom'
require 'temporal/configuration'

Fabricator(:api_history_event, from: Temporal::Api::History::V1::HistoryEvent) do
event_id { 1 }
Expand All @@ -11,10 +10,9 @@
event_type { Temporal::Api::Enums::V1::EventType::EVENT_TYPE_WORKFLOW_EXECUTION_STARTED }
event_time { Time.now }
workflow_execution_started_event_attributes do |attrs|
header_fields = (attrs[:headers] || {}).each_with_object({}) do |(field, value), h|
h[field] = Temporal.configuration.converter.to_payload(value)
end
header = Temporal::Api::Common::V1::Header.new(fields: header_fields)
header = Temporal::Api::Common::V1::Header.new(
fields: $converter.to_payload_map(attrs[:headers] || {})
)

Temporal::Api::History::V1::WorkflowExecutionStartedEventAttributes.new(
workflow_type: Fabricate(:api_workflow_type),
Expand Down
2 changes: 1 addition & 1 deletion spec/fabricators/grpc/memo_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Fabricator(:memo, from: Temporal::Api::Common::V1::Memo) do
fields do
Google::Protobuf::Map.new(:string, :message, Temporal::Api::Common::V1::Payload).tap do |m|
m['foo'] = Temporal.configuration.converter.to_payload('bar')
m['foo'] = $converter.to_payload('bar')
end
end
end
2 changes: 1 addition & 1 deletion spec/fabricators/grpc/search_attributes_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Fabricator(:search_attributes, from: Temporal::Api::Common::V1::SearchAttributes) do
indexed_fields do
Google::Protobuf::Map.new(:string, :message, Temporal::Api::Common::V1::Payload).tap do |m|
m['foo'] = Temporal.configuration.converter.to_payload('bar')
m['foo'] = $converter.to_payload('bar')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
attempt 1
task_queue { Fabricate(:api_task_queue) }
header do |attrs|
fields = (attrs[:headers] || {}).each_with_object({}) do |(field, value), h|
h[field] = Temporal.configuration.converter.to_payload(value)
end
Temporal::Api::Common::V1::Header.new(fields: fields)
Temporal::Api::Common::V1::Header.new(fields: $converter.to_payload_map(attrs[:headers] || {}))
end
end
6 changes: 1 addition & 5 deletions spec/unit/lib/temporal/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,7 @@ class NamespacedWorkflow < Temporal::Workflow
['string', 'a result'],
].each do |(type, expected_result)|
it "completes and returns a #{type}" do
payload = Temporal::Api::Common::V1::Payloads.new(
payloads: [
Temporal.configuration.converter.to_payload(expected_result)
],
)
payload = $converter.to_result_payloads(expected_result)
completed_event = Fabricate(:workflow_completed_event, result: payload)
response = Fabricate(:workflow_execution_history, events: [completed_event])
expect(connection)
Expand Down

0 comments on commit 195fa49

Please sign in to comment.