Class: Minitest::Queue::LazySingleExample

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/queue.rb

Constant Summary collapse

RUNNABLE_METHODS_TRIGGERED =

:nodoc:

Concurrent::Map.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, method_name, file_path, loader:, resolver:, load_error: nil, queue_entry: nil) ⇒ LazySingleExample

Returns a new instance of LazySingleExample.



374
375
376
377
378
379
380
381
382
383
# File 'lib/minitest/queue.rb', line 374

def initialize(class_name, method_name, file_path, loader:, resolver:, load_error: nil, queue_entry: nil)
  @class_name = class_name
  @method_name = method_name
  @file_path = file_path
  @loader = loader
  @resolver = resolver
  @load_error = load_error
  @queue_entry_override = queue_entry
  @runnable = nil
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



372
373
374
# File 'lib/minitest/queue.rb', line 372

def class_name
  @class_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



372
373
374
# File 'lib/minitest/queue.rb', line 372

def file_path
  @file_path
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



372
373
374
# File 'lib/minitest/queue.rb', line 372

def method_name
  @method_name
end

Instance Method Details

#<=>(other) ⇒ Object



393
394
395
# File 'lib/minitest/queue.rb', line 393

def <=>(other)
  id <=> other.id
end

#flaky?Boolean

Returns:

  • (Boolean)


448
449
450
# File 'lib/minitest/queue.rb', line 448

def flaky?
  Minitest.queue.flaky?(self)
end

#idObject



385
386
387
# File 'lib/minitest/queue.rb', line 385

def id
  @id ||= "#{@class_name}##{@method_name}".freeze
end

#marshal_dumpObject



460
461
462
463
464
465
466
467
468
# File 'lib/minitest/queue.rb', line 460

def marshal_dump
  {
    'class_name' => @class_name,
    'method_name' => @method_name,
    'file_path' => @file_path,
    'load_error' => serialize_error(@load_error),
    'queue_entry' => @queue_entry_override,
  }
end

#marshal_load(payload) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/minitest/queue.rb', line 470

def marshal_load(payload)
  @class_name = payload['class_name']
  @method_name = payload['method_name']
  @file_path = payload['file_path']
  @load_error = deserialize_error(payload['load_error'])
  @queue_entry_override = payload['queue_entry']
  @loader = CI::Queue::FileLoader.new
  @resolver = CI::Queue::ClassResolver
  @runnable = nil
  @id = nil
  @queue_entry = nil
end

#queue_entryObject



389
390
391
# File 'lib/minitest/queue.rb', line 389

def queue_entry
  @queue_entry ||= @queue_entry_override || CI::Queue::QueueEntry.format(id, file_path)
end

#runObject



434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/minitest/queue.rb', line 434

def run
  with_timestamps do
    if @load_error
      build_error_result(@load_error)
    elsif skip_stale_tests? && !(runnable.method_defined?(@method_name) || runnable.private_method_defined?(@method_name))
      build_stale_skip_result
    else
      Minitest.run_one_method(runnable, @method_name)
    end
  rescue StandardError, ScriptError => error
    build_error_result(error)
  end
end

#runnableObject



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/minitest/queue.rb', line 399

def runnable
  @runnable ||= begin
    klass = @resolver.resolve(@class_name, file_path: @file_path, loader: @loader)
    unless RUNNABLE_METHODS_TRIGGERED[klass]
      klass.runnable_methods
      RUNNABLE_METHODS_TRIGGERED[klass] = true
    end

    # If the method doesn't exist, the class may have been autoloaded by
    # Zeitwerk without executing test-specific code (includes, helpers).
    # Force load the file so all class-definition-time code executes.
    unless klass.method_defined?(@method_name) || klass.private_method_defined?(@method_name)
      if @file_path && @loader
        @loader.load_file(@file_path)
        RUNNABLE_METHODS_TRIGGERED.delete(klass)
        klass.runnable_methods
        RUNNABLE_METHODS_TRIGGERED[klass] = true
      end
    end

    klass
  end
end

#source_locationObject



452
453
454
455
456
457
458
# File 'lib/minitest/queue.rb', line 452

def source_location
  return nil if @load_error

  runnable.instance_method(@method_name).source_location
rescue NameError, NoMethodError, CI::Queue::FileLoadError, CI::Queue::ClassNotFoundError
  nil
end

#with_timestampsObject



423
424
425
426
427
428
429
430
431
432
# File 'lib/minitest/queue.rb', line 423

def with_timestamps
  start_timestamp = current_timestamp
  result = yield
  result
ensure
  if result
    result.start_timestamp = start_timestamp
    result.finish_timestamp = current_timestamp
  end
end