Class: Dynflow::Testing::InThreadWorld

Inherits:
World
  • Object
show all
Defined in:
lib/dynflow/testing/in_thread_world.rb

Instance Attribute Summary

Attributes inherited from World

#action_classes, #auto_rescue, #auto_validity_check, #client_dispatcher, #clock, #config, #connector, #coordinator, #dead_letter_handler, #delayed_executor, #execution_plan_cleaner, #executor, #executor_dispatcher, #id, #logger_adapter, #meta, #middleware, #persistence, #subscription_index, #terminated, #termination_timeout, #throttle_limiter, #transaction_adapter, #validity_check_timeout

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from World

#action_logger, #auto_execute, #before_termination, #delay, #delay_with_options, #get_execution_status, #logger, #ping, #ping_without_cache, #plan, #plan_with_options, #post_initialization, #publish_request, #registered_world, #reload!, #subscribed_actions, #terminating?, #trigger, #try_spawn, #update_register

Methods included from World::Invalidation

#invalidate, #invalidate_execution_lock, #locks_validity_check, #perform_validity_checks, #with_valid_execution_plan_for_lock, #worlds_validity_check

Constructor Details

#initialize(*args) ⇒ InThreadWorld

Returns a new instance of InThreadWorld.



40
41
42
43
44
# File 'lib/dynflow/testing/in_thread_world.rb', line 40

def initialize(*args)
  super
  @clock = ManagedClock.new
  @executor = InThreadExecutor.new(self)
end

Class Method Details

.coordinator_adapterObject



31
32
33
# File 'lib/dynflow/testing/in_thread_world.rb', line 31

def self.coordinator_adapter
  ->(world, _) { CoordiationAdapterWithLog.new(world) }
end

.instance(&block) ⇒ Object

The worlds created by this method are getting terminated after each test run



36
37
38
# File 'lib/dynflow/testing/in_thread_world.rb', line 36

def self.instance(&block)
  @instance ||= self.new(test_world_config(&block))
end

.logger_adapterObject



27
28
29
# File 'lib/dynflow/testing/in_thread_world.rb', line 27

def self.logger_adapter
  @adapter ||= Dynflow::LoggerAdapters::Simple.new $stderr, 4
end

.persistence_adapterObject



19
20
21
22
23
24
25
# File 'lib/dynflow/testing/in_thread_world.rb', line 19

def self.persistence_adapter
  @persistence_adapter ||= begin
                             db_config = ENV['DB_CONN_STRING'] || 'sqlite:/'
                             puts "Using database configuration: #{db_config}"
                             Dynflow::PersistenceAdapters::Sequel.new(db_config)
                           end
end

.test_world_config {|config| ... } ⇒ Object

Yields:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dynflow/testing/in_thread_world.rb', line 4

def self.test_world_config
  config                     = Dynflow::Config.new
  config.persistence_adapter = persistence_adapter
  config.logger_adapter      = logger_adapter
  config.coordinator_adapter = coordinator_adapter
  config.delayed_executor    = nil
  config.auto_rescue         = false
  config.auto_validity_check = false
  config.exit_on_terminate   = false
  config.auto_execute        = false
  config.auto_terminate      = false
  yield config if block_given?
  return config
end

Instance Method Details

#event(execution_plan_id, step_id, event, done = Concurrent::Promises.resolvable_future) ⇒ Object



60
61
62
# File 'lib/dynflow/testing/in_thread_world.rb', line 60

def event(execution_plan_id, step_id, event, done = Concurrent::Promises.resolvable_future)
  @executor.event(execution_plan_id, step_id, event, done)
end

#execute(execution_plan_id, done = Concurrent::Promises.resolvable_future) ⇒ Object



46
47
48
# File 'lib/dynflow/testing/in_thread_world.rb', line 46

def execute(execution_plan_id, done = Concurrent::Promises.resolvable_future)
  @executor.execute(execution_plan_id, done)
end

#terminate(future = Concurrent::Promises.resolvable_future) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/dynflow/testing/in_thread_world.rb', line 50

def terminate(future = Concurrent::Promises.resolvable_future)
  run_before_termination_hooks
  @executor.terminate
  coordinator.delete_world(registered_world)
  future.fulfill true
  @terminated.resolve
rescue => e
  future.reject e
end