Class: Megatest::Config
- Inherits:
-
Object
- Object
- Megatest::Config
- Defined in:
- lib/megatest/config.rb
Constant Summary collapse
- NOT_SERIALIZED =
%i(@job_teardown_callbacks @job_setup_callbacks @global_setup_callbacks).freeze
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#before_fork_callbacks ⇒ Object
readonly
Returns the value of attribute before_fork_callbacks.
-
#build_id ⇒ Object
Returns the value of attribute build_id.
-
#ci ⇒ Object
Returns the value of attribute ci.
-
#circuit_breaker ⇒ Object
readonly
Returns the value of attribute circuit_breaker.
- #colors(io = nil) ⇒ Object
-
#deprecations ⇒ Object
Returns the value of attribute deprecations.
-
#differ ⇒ Object
writeonly
Sets the attribute differ.
-
#global_setup_callbacks ⇒ Object
readonly
Returns the value of attribute global_setup_callbacks.
-
#heartbeat_frequency ⇒ Object
Returns the value of attribute heartbeat_frequency.
-
#job_index ⇒ Object
Returns the value of attribute job_index.
- #jobs_count ⇒ Object
-
#load_paths ⇒ Object
Returns the value of attribute load_paths.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#minitest_compatibility ⇒ Object
Returns the value of attribute minitest_compatibility.
-
#pretty_printer ⇒ Object
writeonly
Sets the attribute pretty_printer.
- #program_name ⇒ Object
-
#queue_url ⇒ Object
Returns the value of attribute queue_url.
-
#retry_tolerance ⇒ Object
Returns the value of attribute retry_tolerance.
-
#seed ⇒ Object
Returns the value of attribute seed.
-
#selectors ⇒ Object
Returns the value of attribute selectors.
-
#test_globs ⇒ Object
Returns the value of attribute test_globs.
-
#worker_id ⇒ Object
Returns the value of attribute worker_id.
-
#workers_count ⇒ Object
Returns the value of attribute workers_count.
Instance Method Summary collapse
- #before_fork(&block) ⇒ Object
- #build_queue ⇒ Object
- #diff(expected, actual) ⇒ Object
- #global_setup(&block) ⇒ Object
-
#initialize(env) ⇒ Config
constructor
A new instance of Config.
- #initialize_dup(_) ⇒ Object
- #job_setup(&block) ⇒ Object
- #job_teardown(&block) ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
- #max_consecutive_failures=(max) ⇒ Object
- #parallelize_maybe ⇒ Object
-
#random ⇒ Object
We always return a new generator with the same seed as to best reproduce remote builds locally if the same seed is given.
- #render_object(object) ⇒ Object
- #retries? ⇒ Boolean
- #run_before_fork_callback ⇒ Object
- #run_global_setup_callbacks ⇒ Object
- #run_job_setup_callbacks(job_index) ⇒ Object
- #run_job_teardown_callbacks(job_index) ⇒ Object
- #total_max_retries(size) ⇒ Object
- #valid_worker_index? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Config
Returns a new instance of Config.
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/megatest/config.rb', line 145 def initialize(env) @load_paths = ["test"] # For easier transition from other frameworks @retry_tolerance = 0.0 @max_retries = 0 @deprecations = true @full_backtrace = false @queue_url = nil @ci = false @build_id = nil @worker_id = nil @workers_count = 1 @jobs_count = nil @colors = nil # auto @before_fork_callbacks = [] @global_setup_callbacks = [] @job_setup_callbacks = [] @job_teardown_callbacks = [] @heartbeat_frequency = 5 @backtrace = Backtrace.new @program_name = nil @circuit_breaker = CircuitBreaker.new(Float::INFINITY) @seed = Random.rand(0xFFFF) @differ = Differ.new(self) @pretty_printer = PrettyPrint.new(self) @minitest_compatibility = false @selectors = nil @test_globs = [DEFAULT_TEST_GLOB] CIService.configure(self, env) end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def backtrace @backtrace end |
#before_fork_callbacks ⇒ Object (readonly)
Returns the value of attribute before_fork_callbacks.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def before_fork_callbacks @before_fork_callbacks end |
#build_id ⇒ Object
Returns the value of attribute build_id.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def build_id @build_id end |
#ci ⇒ Object
Returns the value of attribute ci.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def ci @ci end |
#circuit_breaker ⇒ Object (readonly)
Returns the value of attribute circuit_breaker.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def circuit_breaker @circuit_breaker end |
#colors(io = nil) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/megatest/config.rb', line 224 def colors(io = nil) case @colors when true Output::ANSIColors when false Output::NoColors else if io && !io.tty? Output::NoColors else Output::ANSIColors end end end |
#deprecations ⇒ Object
Returns the value of attribute deprecations.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def deprecations @deprecations end |
#differ=(value) ⇒ Object (writeonly)
Sets the attribute differ
143 144 145 |
# File 'lib/megatest/config.rb', line 143 def differ=(value) @differ = value end |
#global_setup_callbacks ⇒ Object (readonly)
Returns the value of attribute global_setup_callbacks.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def global_setup_callbacks @global_setup_callbacks end |
#heartbeat_frequency ⇒ Object
Returns the value of attribute heartbeat_frequency.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def heartbeat_frequency @heartbeat_frequency end |
#job_index ⇒ Object
Returns the value of attribute job_index.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def job_index @job_index end |
#jobs_count ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/megatest/config.rb', line 189 def jobs_count if @jobs_count == :number_of_processors if Megatest.fork? require "etc" nprocessors = Etc.nprocessors jobs = [nprocessors, cgroups_cpu_quota&.to_i || nprocessors].min @jobs_count = [jobs, 1].max else @jobs_count = 1 end end @jobs_count ||= 1 end |
#load_paths ⇒ Object
Returns the value of attribute load_paths.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def load_paths @load_paths end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def max_retries @max_retries end |
#minitest_compatibility ⇒ Object
Returns the value of attribute minitest_compatibility.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def minitest_compatibility @minitest_compatibility end |
#pretty_printer=(value) ⇒ Object (writeonly)
Sets the attribute pretty_printer
143 144 145 |
# File 'lib/megatest/config.rb', line 143 def pretty_printer=(value) @pretty_printer = value end |
#program_name ⇒ Object
185 186 187 |
# File 'lib/megatest/config.rb', line 185 def program_name @program_name || "megatest" end |
#queue_url ⇒ Object
Returns the value of attribute queue_url.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def queue_url @queue_url end |
#retry_tolerance ⇒ Object
Returns the value of attribute retry_tolerance.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def retry_tolerance @retry_tolerance end |
#seed ⇒ Object
Returns the value of attribute seed.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def seed @seed end |
#selectors ⇒ Object
Returns the value of attribute selectors.
139 140 141 |
# File 'lib/megatest/config.rb', line 139 def selectors @selectors end |
#test_globs ⇒ Object
Returns the value of attribute test_globs.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def test_globs @test_globs end |
#worker_id ⇒ Object
Returns the value of attribute worker_id.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def worker_id @worker_id end |
#workers_count ⇒ Object
Returns the value of attribute workers_count.
141 142 143 |
# File 'lib/megatest/config.rb', line 141 def workers_count @workers_count end |
Instance Method Details
#before_fork(&block) ⇒ Object
281 282 283 |
# File 'lib/megatest/config.rb', line 281 def before_fork(&block) @before_fork_callbacks << block end |
#build_queue ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/megatest/config.rb', line 261 def build_queue case @queue_url when nil Queue.build(self) when /\Arediss?:/ require "megatest/redis_queue" RedisQueue.build(self) else if @queue_url.is_a?(String) && File.exist?(@queue_url) FileQueue.build(self) else raise ArgumentError, "Unsupported queue type: #{@queue_url.inspect}" end end end |
#diff(expected, actual) ⇒ Object
243 244 245 |
# File 'lib/megatest/config.rb', line 243 def diff(expected, actual) @differ&.call(expected, actual) end |
#global_setup(&block) ⇒ Object
289 290 291 |
# File 'lib/megatest/config.rb', line 289 def global_setup(&block) @global_setup_callbacks << block end |
#initialize_dup(_) ⇒ Object
179 180 181 182 183 |
# File 'lib/megatest/config.rb', line 179 def initialize_dup(_) super @circuit_breaker = @circuit_breaker.dup @test_globs = @test_globs.dup end |
#job_setup(&block) ⇒ Object
297 298 299 |
# File 'lib/megatest/config.rb', line 297 def job_setup(&block) @job_setup_callbacks << block end |
#job_teardown(&block) ⇒ Object
305 306 307 |
# File 'lib/megatest/config.rb', line 305 def job_teardown(&block) @job_teardown_callbacks << block end |
#marshal_dump ⇒ Object
322 323 324 325 326 |
# File 'lib/megatest/config.rb', line 322 def marshal_dump instance_variables.reject { |k| NOT_SERIALIZED.include?(k) }.to_h do |name| [name, instance_variable_get(name)] end end |
#marshal_load(hash) ⇒ Object
328 329 330 331 332 |
# File 'lib/megatest/config.rb', line 328 def marshal_load(hash) hash.each do |name, value| instance_variable_set(name, value) end end |
#max_consecutive_failures=(max) ⇒ Object
239 240 241 |
# File 'lib/megatest/config.rb', line 239 def max_consecutive_failures=(max) @circuit_breaker = CircuitBreaker.new(max) end |
#parallelize_maybe ⇒ Object
203 204 205 206 |
# File 'lib/megatest/config.rb', line 203 def parallelize_maybe @jobs_count ||= :number_of_processors if Megatest.fork? self end |
#random ⇒ Object
We always return a new generator with the same seed as to best reproduce remote builds locally if the same seed is given.
253 254 255 |
# File 'lib/megatest/config.rb', line 253 def random Random.new(@seed) end |
#render_object(object) ⇒ Object
247 248 249 |
# File 'lib/megatest/config.rb', line 247 def render_object(object) @pretty_printer.pretty_print(object) end |
#retries? ⇒ Boolean
309 310 311 |
# File 'lib/megatest/config.rb', line 309 def retries? @max_retries.positive? end |
#run_before_fork_callback ⇒ Object
277 278 279 |
# File 'lib/megatest/config.rb', line 277 def run_before_fork_callback @before_fork_callback.each { |c| c.call(self) } end |
#run_global_setup_callbacks ⇒ Object
285 286 287 |
# File 'lib/megatest/config.rb', line 285 def run_global_setup_callbacks @global_setup_callbacks.each { |c| c.call(self) } end |
#run_job_setup_callbacks(job_index) ⇒ Object
293 294 295 |
# File 'lib/megatest/config.rb', line 293 def run_job_setup_callbacks(job_index) @job_setup_callbacks.each { |c| c.call(self, job_index) } end |
#run_job_teardown_callbacks(job_index) ⇒ Object
301 302 303 |
# File 'lib/megatest/config.rb', line 301 def run_job_teardown_callbacks(job_index) @job_teardown_callbacks.each { |c| c.call(self, job_index) } end |
#total_max_retries(size) ⇒ Object
313 314 315 316 317 318 319 |
# File 'lib/megatest/config.rb', line 313 def total_max_retries(size) if @retry_tolerance.positive? (size * @retry_tolerance).ceil else @max_retries * size end end |
#valid_worker_index? ⇒ Boolean
220 221 222 |
# File 'lib/megatest/config.rb', line 220 def valid_worker_index? worker_id.is_a?(Integer) && worker_id.positive? && worker_id < workers_count end |