Class: Minitest::Distributed::Coordinators::MemoryCoordinator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
CoordinatorInterface
Defined in:
lib/minitest/distributed/coordinators/memory_coordinator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:) ⇒ MemoryCoordinator

Returns a new instance of MemoryCoordinator.



23
24
25
26
27
28
29
30
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 23

def initialize(configuration:)
  @configuration = configuration

  @leader = T.let(Mutex.new, Mutex)
  @queue = T.let(Queue.new, Queue)
  @local_results = T.let(ResultAggregate.new(max_failures: configuration.max_failures), ResultAggregate)
  @aborted = T.let(false, T::Boolean)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



12
13
14
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 12

def configuration
  @configuration
end

#local_resultsObject (readonly) Also known as: combined_results

Returns the value of attribute local_results.



18
19
20
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 18

def local_results
  @local_results
end

#queueObject (readonly)

Returns the value of attribute queue.



15
16
17
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 15

def queue
  @queue
end

Instance Method Details

#aborted?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 38

def aborted?
  @aborted
end

#consume(reporter:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 63

def consume(reporter:)
  until queue.closed?
    enqueued_runnable = T.let(queue.pop, EnqueuedRunnable)

    reporter.prerecord(enqueued_runnable.runnable_class, enqueued_runnable.method_name)

    initial_result = enqueued_runnable.run
    enqueued_result = enqueued_runnable.commit_result(initial_result) do |result_to_commit|
      if ResultType.of(result_to_commit) == ResultType::Requeued
        queue << enqueued_runnable.next_attempt
      end
      EnqueuedRunnable::Result::Commit.success
    end

    reporter.record(enqueued_result.committed_result)
    local_results.update_with_result(enqueued_result)

    # We abort a run if we reach the maximum number of failures
    queue.close if combined_results.abort?
    queue.close if combined_results.complete?
  end
end

#produce(test_selector:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 43

def produce(test_selector:)
  if @leader.try_lock
    tests = test_selector.tests
    @local_results.size = tests.size
    if tests.empty?
      queue.close
    else
      tests.each do |runnable|
        queue << EnqueuedRunnable.new(
          class_name: T.must(runnable.class.name),
          method_name: runnable.name,
          test_timeout_seconds: configuration.test_timeout_seconds,
          max_attempts: configuration.max_attempts,
        )
      end
    end
  end
end

#register_reporters(reporter:, options:) ⇒ Object



33
34
35
# File 'lib/minitest/distributed/coordinators/memory_coordinator.rb', line 33

def register_reporters(reporter:, options:)
  # No need for any additional reporters
end