Module: Minitest
- Defined in:
- lib/minitest/parallel_fork/interrupt.rb,
lib/minitest/parallel_fork.rb
Defined Under Namespace
Modules: ParalleForkFailFast, ParallelForkHalt, ParallelForkInterrupt, Unparallelize
Class Attribute Summary collapse
Class Method Summary
collapse
-
.after_parallel_fork(i = nil, &block) ⇒ Object
Set the after_parallel_fork block to the given block.
-
.before_parallel_fork(&block) ⇒ Object
Set the before_parallel_fork block to the given block.
-
.on_parallel_fork_marshal_failure(&block) ⇒ Object
Set the on_parallel_fork_marshal_failure block to the given block.
-
.parallel_fork_child_data(data) ⇒ Object
-
.parallel_fork_data_from_marshal(data) ⇒ Object
-
.parallel_fork_data_to_marshal ⇒ Object
-
.parallel_fork_fork_child(i, suites, reporter, options) ⇒ Object
-
.parallel_fork_number ⇒ Object
-
.parallel_fork_run_test_suite(suite, reporter, options) ⇒ Object
-
.parallel_fork_run_test_suites(suites, reporter, options) ⇒ Object
-
.parallel_fork_setup_children(suites, reporter, options) ⇒ Object
-
.parallel_fork_suites ⇒ Object
-
.parallel_fork_wait_for_children(child_info, reporter) ⇒ Object
-
.run_after_parallel_fork_hook(i) ⇒ Object
-
.run_before_parallel_fork_hook ⇒ Object
-
.set_parallel_fork_stat_reporter(reporter) ⇒ Object
Class Attribute Details
.parallel_fork_stat_reporter ⇒ Object
Returns the value of attribute parallel_fork_stat_reporter.
32
33
34
|
# File 'lib/minitest/parallel_fork.rb', line 32
def parallel_fork_stat_reporter
@parallel_fork_stat_reporter
end
|
Class Method Details
.after_parallel_fork(i = nil, &block) ⇒ Object
Set the after_parallel_fork block to the given block
23
24
25
|
# File 'lib/minitest/parallel_fork.rb', line 23
def after_parallel_fork(i=nil, &block)
@after_parallel_fork = block
end
|
.before_parallel_fork(&block) ⇒ Object
Set the before_parallel_fork block to the given block
18
19
20
|
# File 'lib/minitest/parallel_fork.rb', line 18
def before_parallel_fork(&block)
@before_parallel_fork = block
end
|
.on_parallel_fork_marshal_failure(&block) ⇒ Object
Set the on_parallel_fork_marshal_failure block to the given block
28
29
30
|
# File 'lib/minitest/parallel_fork.rb', line 28
def on_parallel_fork_marshal_failure(&block)
@on_parallel_fork_marshal_failure = block
end
|
.parallel_fork_child_data(data) ⇒ Object
116
117
118
|
# File 'lib/minitest/parallel_fork.rb', line 116
def parallel_fork_child_data(data)
data.map{|_pid, read| Thread.new(read, &:read)}.map(&:value).map{|data| parallel_fork_data_from_marshal(data)}
end
|
.parallel_fork_data_from_marshal(data) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/minitest/parallel_fork.rb', line 60
def parallel_fork_data_from_marshal(data)
Marshal.load(data)
rescue ArgumentError
if @on_parallel_fork_marshal_failure
@on_parallel_fork_marshal_failure.call
end
raise
end
|
.parallel_fork_data_to_marshal ⇒ Object
56
57
58
|
# File 'lib/minitest/parallel_fork.rb', line 56
def parallel_fork_data_to_marshal
i'count assertions results'.map{|meth| parallel_fork_stat_reporter.send(meth)}
end
|
.parallel_fork_fork_child(i, suites, reporter, options) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/minitest/parallel_fork.rb', line 98
def parallel_fork_fork_child(i, suites, reporter, options)
read, write = IO.pipe.each{|io| io.binmode}
pid = Process.fork do
read.close
run_after_parallel_fork_hook(i)
p_suites = []
n = parallel_fork_number
suites.each_with_index{|s, j| p_suites << s if j % n == i}
parallel_fork_run_test_suites(p_suites, reporter, options)
write.write(Marshal.dump(parallel_fork_data_to_marshal))
write.close
end
write.close
[pid, read]
end
|
.parallel_fork_number ⇒ Object
132
133
134
|
# File 'lib/minitest/parallel_fork.rb', line 132
def parallel_fork_number
(ENV['NCPU'] || 4).to_i
end
|
.parallel_fork_run_test_suite(suite, reporter, options) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/minitest/parallel_fork.rb', line 75
def parallel_fork_run_test_suite(suite, reporter, options)
if suite.is_a?(Minitest::Parallel::Test::ClassMethods)
suite.extend(Minitest::Unparallelize)
end
if Minitest::VERSION >= '6'
suite.run_suite(reporter, options)
else
suite.run(reporter, options)
end
end
|
.parallel_fork_run_test_suites(suites, reporter, options) ⇒ Object
69
70
71
72
73
|
# File 'lib/minitest/parallel_fork.rb', line 69
def parallel_fork_run_test_suites(suites, reporter, options)
suites.each do |suite|
parallel_fork_run_test_suite(suite, reporter, options)
end
end
|
.parallel_fork_setup_children(suites, reporter, options) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/minitest/parallel_fork.rb', line 89
def parallel_fork_setup_children(suites, reporter, options)
set_parallel_fork_stat_reporter(reporter)
run_before_parallel_fork_hook
parallel_fork_number.times.map do |i|
parallel_fork_fork_child(i, suites, reporter, options)
end
end
|
.parallel_fork_suites ⇒ Object
40
41
42
|
# File 'lib/minitest/parallel_fork.rb', line 40
def parallel_fork_suites
Minitest::Runnable.runnables.shuffle
end
|
.parallel_fork_wait_for_children(child_info, reporter) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/minitest/parallel_fork.rb', line 120
def parallel_fork_wait_for_children(child_info, reporter)
parallel_fork_child_data(child_info).each do |data|
count, assertions, results = data
reporter.reporters.each do |rep|
next unless i'count assertions results count= assertions='.all?{|meth| rep.respond_to?(meth)}
rep.count += count
rep.assertions += assertions
rep.results.concat(results)
end
end
end
|
.run_after_parallel_fork_hook(i) ⇒ Object
50
51
52
53
54
|
# File 'lib/minitest/parallel_fork.rb', line 50
def run_after_parallel_fork_hook(i)
if @after_parallel_fork
@after_parallel_fork.call(i)
end
end
|
.run_before_parallel_fork_hook ⇒ Object
44
45
46
47
48
|
# File 'lib/minitest/parallel_fork.rb', line 44
def run_before_parallel_fork_hook
if @before_parallel_fork
@before_parallel_fork.call
end
end
|
.set_parallel_fork_stat_reporter(reporter) ⇒ Object
34
35
36
37
38
|
# File 'lib/minitest/parallel_fork.rb', line 34
def set_parallel_fork_stat_reporter(reporter)
@parallel_fork_stat_reporter = reporter.reporters.detect do |rep|
%w'count assertions results count= assertions='.all?{|meth| rep.respond_to?(meth)}
end
end
|