Module: DistribCore::Configuration

Defined in:
lib/distrib_core/configuration.rb

Overview

This module contains shared attrs instantiated by specific configuration classes.

See Also:

Constant Summary collapse

TIMEOUT_STRATEGIES =
%i[repush release].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#before_test_reportObject

Examples:

Specify custom block to pre-process examples before reporting them to the leader. Useful to add additional information about workers.

...configure do |config|
  config.before_test_report = -> (file_name, example_groups) do
    example_groups.each { |eg| eg.[:custom] = 'foo' }
  end
end


76
77
78
# File 'lib/distrib_core/configuration.rb', line 76

def before_test_report
  @before_test_report
end

#debug_loggerLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Debugging logger. However user configures ‘logger`, this one collects messages logged at all levels.

Returns:

  • (Logger)


157
158
159
# File 'lib/distrib_core/configuration.rb', line 157

def debug_logger
  @debug_logger ||= Logger.new('distrib.log', level: :debug)
end

#drbObject

Examples:

Specify custom options for DRb service. Defaults are ‘{ safe_level: 1 }`. @see `DRb::DRbServer.new` for complete list

...configure do |config|
  config.drb = {safe_level: 0, verbose: true}
end


68
69
70
# File 'lib/distrib_core/configuration.rb', line 68

def drb
  @drb
end

#drb_tcp_socket_connection_timeoutObject

Returns the value of attribute drb_tcp_socket_connection_timeout.



92
93
94
# File 'lib/distrib_core/configuration.rb', line 92

def drb_tcp_socket_connection_timeout
  @drb_tcp_socket_connection_timeout
end

#error_handlerObject

Object to handle errors from workers



116
117
118
# File 'lib/distrib_core/configuration.rb', line 116

def error_handler
  @error_handler || raise(NotImplementedError)
end

#first_test_picked_timeoutObject

Examples:

Set how long leader will wait before first test processed by workers. Leader will exit if no tests picked in this period

...configure do |config|
  config.first_test_picked_timeout = 10*60 # 10 minutes
end


62
63
64
# File 'lib/distrib_core/configuration.rb', line 62

def first_test_picked_timeout
  @first_test_picked_timeout
end

#leader_connection_attemptsObject

Returns the value of attribute leader_connection_attempts.



92
93
94
# File 'lib/distrib_core/configuration.rb', line 92

def leader_connection_attempts
  @leader_connection_attempts
end

#loggerLogger

Returns:

  • (Logger)


131
132
133
# File 'lib/distrib_core/configuration.rb', line 131

def logger
  @logger ||= Logger.new($stdout, level: :info)
end

#on_finishObject

Examples:

Specify custom block which will be called on leader after run.

...configure do |config|
  config.on_finish = -> () do
    'Whatever logic before leader exit'
  end
end


84
85
86
# File 'lib/distrib_core/configuration.rb', line 84

def on_finish
  @on_finish
end

#test_timeoutObject

Examples:

Set equal timeout for all tests to 30 seconds:

...configure do |config|
  config.test_timeout = 30 # seconds
end

Or you can specify timeout per test. An object that responds to ‘call` and receives the test as an argument. The proc returns the timeout in seconds.

...configure do |config|
  config.test_timeout = ->(test) do
    10 + 2 * average_execution_in_seconds(test)
  end
end


56
57
58
# File 'lib/distrib_core/configuration.rb', line 56

def test_timeout
  @test_timeout
end

#tests_processing_stopped_timeoutObject

Returns the value of attribute tests_processing_stopped_timeout.



92
93
94
# File 'lib/distrib_core/configuration.rb', line 92

def tests_processing_stopped_timeout
  @tests_processing_stopped_timeout
end

#tests_providerProc, Object#call

Provider for tests to execute

Returns:

  • (Proc, Object#call)

    an object which responds to ‘#call`



111
112
113
# File 'lib/distrib_core/configuration.rb', line 111

def tests_provider
  @tests_provider || raise(NotImplementedError)
end

#timeout_strategyObject

Returns the value of attribute timeout_strategy.



93
94
95
# File 'lib/distrib_core/configuration.rb', line 93

def timeout_strategy
  @timeout_strategy
end

Class Method Details

.currentDistribCore::Configuration

Returns global configuration.

Returns:



22
23
24
# File 'lib/distrib_core/configuration.rb', line 22

def current
  @current || raise('Configuration is not set')
end

.current=(configuration) ⇒ Object

Set global configuration. Can be set only one time

Parameters:



15
16
17
18
19
# File 'lib/distrib_core/configuration.rb', line 15

def current=(configuration)
  raise('Configuration is already set') if @current && @current != configuration

  @current = configuration
end

Instance Method Details

#broadcasterLoggerBroadcaster

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Main logging interface used by distrib.

Returns:



148
149
150
# File 'lib/distrib_core/configuration.rb', line 148

def broadcaster
  @broadcaster ||= LoggerBroadcaster.new([logger, debug_logger])
end

#initializeObject

Initialize configuration with default values and set it to current



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/distrib_core/configuration.rb', line 96

def initialize
  DistribCore::Configuration.current = self

  @test_timeout = 60 # 1 minute
  @first_test_picked_timeout = 10 * 60 # 10 minutes
  @tests_processing_stopped_timeout = 5 * 60 # 5 minutes
  @drb = { safe_level: 1 }
  @drb_tcp_socket_connection_timeout = 5 # 5 seconds
  @leader_connection_attempts = 200
  self.timeout_strategy = :repush
end

#timeout_for(test) ⇒ Float

Gives a timeout for a particular test based on ‘#test_timeout`

Parameters:

  • test (String)

    a test

Returns:

  • (Float)

    timeout in seconds

See Also:



126
127
128
# File 'lib/distrib_core/configuration.rb', line 126

def timeout_for(test)
  test_timeout.respond_to?(:call) ? test_timeout.call(test) : test_timeout
end