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.



386
387
388
389
390
391
392
393
394
395
# File 'lib/minitest/queue.rb', line 386

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.



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

def class_name
  @class_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

Instance Method Details

#<=>(other) ⇒ Object



405
406
407
# File 'lib/minitest/queue.rb', line 405

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

#flaky?Boolean

Returns:

  • (Boolean)


460
461
462
# File 'lib/minitest/queue.rb', line 460

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

#idObject



397
398
399
# File 'lib/minitest/queue.rb', line 397

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

#marshal_dumpObject



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

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



482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/minitest/queue.rb', line 482

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



401
402
403
# File 'lib/minitest/queue.rb', line 401

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

#runObject



446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/minitest/queue.rb', line 446

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



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/minitest/queue.rb', line 411

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



464
465
466
467
468
469
470
# File 'lib/minitest/queue.rb', line 464

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



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

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