Module: Cadence::Testing::CadenceOverride

Defined in:
lib/cadence/testing/cadence_override.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(_mod) ⇒ Object


13
14
15
16
# File 'lib/cadence/testing/cadence_override.rb', line 13

def self.prepended(_mod)
  # Allow firing timers in testing mode via Cadence API
  Cadence.def_delegators(:default_client, :fire_timer)
end

Instance Method Details

#complete_activity(async_token, result = nil) ⇒ Object


42
43
44
45
46
47
48
49
# File 'lib/cadence/testing/cadence_override.rb', line 42

def complete_activity(async_token, result = nil)
  return super if Cadence::Testing.disabled?

  details = Activity::AsyncToken.decode(async_token)
  execution = executions[[details.workflow_id, details.run_id]]

  execution.complete_future(details.activity_id, result)
end

#fail_activity(async_token, error) ⇒ Object


51
52
53
54
55
56
57
58
# File 'lib/cadence/testing/cadence_override.rb', line 51

def fail_activity(async_token, error)
  return super if Cadence::Testing.disabled?

  details = Activity::AsyncToken.decode(async_token)
  execution = executions[[details.workflow_id, details.run_id]]

  execution.fail_future(details.activity_id, error)
end

#fetch_workflow_execution_info(_domain, workflow_id, run_id) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cadence/testing/cadence_override.rb', line 26

def fetch_workflow_execution_info(_domain, workflow_id, run_id)
  return super if Cadence::Testing.disabled?

  execution = executions[[workflow_id, run_id]]

  Workflow::ExecutionInfo.new(
    workflow: nil,
    workflow_id: workflow_id,
    run_id: run_id,
    start_time: nil,
    close_time: nil,
    status: execution.status,
    history_length: nil,
  ).freeze
end

#fire_timer(workflow_id, run_id, timer_id) ⇒ Object

This method is only available in teesting mode


61
62
63
64
65
# File 'lib/cadence/testing/cadence_override.rb', line 61

def fire_timer(workflow_id, run_id, timer_id)
  execution = executions[[workflow_id, run_id]]

  execution.complete_future(timer_id)
end

#start_workflow(workflow, *input, **args) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/cadence/testing/cadence_override.rb', line 18

def start_workflow(workflow, *input, **args)
  return super if Cadence::Testing.disabled?

  if Cadence::Testing.local?
    start_locally(workflow, *input, **args)
  end
end