Module: Minitest::ParallelForkHalt

Included in:
ParalleForkFailFast, ParallelForkInterrupt
Defined in:
lib/minitest/parallel_fork/halt.rb

Instance Method Summary collapse

Instance Method Details

#parallel_fork_child_data(data) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/minitest/parallel_fork/halt.rb', line 29

def parallel_fork_child_data(data)
  threads = {}
  data.each{|pid, read| threads[pid] = Thread.new(read, &:read)}
  results = []

  while sleep(0.01) && !threads.empty?
    threads.to_a.each do |pid, thread|
      unless thread.alive?
        threads.delete(pid)
        results << parallel_fork_data_from_marshal(thread.value)

        if @parallel_fork_stop
          # If halt is requested, signal other children to halt
          threads.each_key do |pid|
            Process.kill(:USR1, pid)
          end

          # Set a flag indicating that all child processes have been signaled
          @parallel_fork_stop = :FINISHED
        end
      end
    end
  end

  results
end

#parallel_fork_data_from_marshal(data) ⇒ Object



13
14
15
16
17
# File 'lib/minitest/parallel_fork/halt.rb', line 13

def parallel_fork_data_from_marshal(data)
  data = Marshal.load(data)
  @parallel_fork_stop = true if data.pop
  data
end

#parallel_fork_data_to_marshalObject



9
10
11
# File 'lib/minitest/parallel_fork/halt.rb', line 9

def parallel_fork_data_to_marshal
  super << @parallel_fork_stop
end

#parallel_fork_run_test_suites(suites, reporter, options) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/minitest/parallel_fork/halt.rb', line 19

def parallel_fork_run_test_suites(suites, reporter, options)
  suites.each do |suite|
    parallel_fork_run_test_suite(suite, reporter, options)

    # Halt if this child process requested an exit,
    # Or other child processes requested an exit.
    break if @parallel_fork_stop
  end
end

#run_after_parallel_fork_hook(i) ⇒ Object



2
3
4
5
6
7
# File 'lib/minitest/parallel_fork/halt.rb', line 2

def run_after_parallel_fork_hook(i)
  super
  Signal.trap(:USR1) do
    @parallel_fork_stop = true
  end
end