test-unit 3.7.8 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/text/news.md +147 -0
- data/lib/test/unit/assertions.rb +75 -2
- data/lib/test/unit/attribute.rb +8 -5
- data/lib/test/unit/autorunner.rb +10 -0
- data/lib/test/unit/collector/descendant.rb +2 -2
- data/lib/test/unit/collector/load.rb +53 -7
- data/lib/test/unit/collector.rb +2 -3
- data/lib/test/unit/color-scheme.rb +70 -66
- data/lib/test/unit/color.rb +3 -1
- data/lib/test/unit/diff.rb +2 -2
- data/lib/test/unit/error.rb +15 -4
- data/lib/test/unit/failure.rb +1 -1
- data/lib/test/unit/fault-location-detector.rb +1 -3
- data/lib/test/unit/fixture.rb +9 -0
- data/lib/test/unit/omission.rb +22 -0
- data/lib/test/unit/priority.rb +2 -1
- data/lib/test/unit/process-test-result.rb +6 -0
- data/lib/test/unit/process-worker.rb +10 -3
- data/lib/test/unit/ractor-helper.rb +46 -0
- data/lib/test/unit/ractor-test-result.rb +60 -0
- data/lib/test/unit/sub-test-result.rb +6 -0
- data/lib/test/unit/test-finder.rb +44 -0
- data/lib/test/unit/test-ractor-run-context.rb +23 -0
- data/lib/test/unit/test-suite-creator.rb +3 -2
- data/lib/test/unit/test-suite-process-runner.rb +5 -2
- data/lib/test/unit/test-suite-ractor-runner.rb +189 -0
- data/lib/test/unit/test-suite-runner.rb +4 -0
- data/lib/test/unit/test-suite-thread-runner.rb +20 -8
- data/lib/test/unit/testcase.rb +149 -22
- data/lib/test/unit/testresult.rb +11 -4
- data/lib/test/unit/testsuite.rb +25 -12
- data/lib/test/unit/ui/testrunnermediator.rb +3 -3
- data/lib/test/unit/util/backtracefilter.rb +7 -0
- data/lib/test/unit/util/observable.rb +1 -1
- data/lib/test/unit/util/output.rb +41 -10
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit/worker-context.rb +7 -0
- data/lib/test/unit.rb +25 -0
- metadata +7 -2
data/lib/test/unit/error.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
#--
|
|
2
3
|
#
|
|
3
4
|
# Author:: Nathaniel Talbott.
|
|
@@ -76,15 +77,24 @@ module Test
|
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
|
|
79
|
-
NOT_PASS_THROUGH_EXCEPTIONS = []
|
|
80
|
-
NOT_PASS_THROUGH_EXCEPTION_NAMES = ["Timeout::Error"]
|
|
80
|
+
NOT_PASS_THROUGH_EXCEPTIONS = [].freeze
|
|
81
|
+
NOT_PASS_THROUGH_EXCEPTION_NAMES = ["Timeout::Error"].freeze
|
|
81
82
|
PASS_THROUGH_EXCEPTIONS = [
|
|
82
83
|
NoMemoryError,
|
|
83
84
|
SignalException,
|
|
84
85
|
Interrupt,
|
|
85
86
|
SystemExit,
|
|
86
|
-
]
|
|
87
|
-
PASS_THROUGH_EXCEPTION_NAMES = []
|
|
87
|
+
].freeze
|
|
88
|
+
PASS_THROUGH_EXCEPTION_NAMES = [].freeze
|
|
89
|
+
|
|
90
|
+
# Returns whether an error occurred in the test. This is for
|
|
91
|
+
# Minitest compatibility.
|
|
92
|
+
#
|
|
93
|
+
# @return [Boolean]
|
|
94
|
+
def error?
|
|
95
|
+
@internal_data.errored?
|
|
96
|
+
end
|
|
97
|
+
|
|
88
98
|
private
|
|
89
99
|
def handle_all_exception(exception)
|
|
90
100
|
return false if pass_through_exception?(exception)
|
|
@@ -117,6 +127,7 @@ module Test
|
|
|
117
127
|
end
|
|
118
128
|
|
|
119
129
|
def add_error(exception)
|
|
130
|
+
@internal_data.errored
|
|
120
131
|
error = Error.new(name, exception, :method_name => @method_name)
|
|
121
132
|
current_result.add_error(error)
|
|
122
133
|
end
|
data/lib/test/unit/failure.rb
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
#
|
|
3
3
|
# License: Ruby's
|
|
4
4
|
|
|
5
|
-
require "English"
|
|
6
|
-
|
|
7
5
|
module Test
|
|
8
6
|
module Unit
|
|
9
7
|
class FaultLocationDetector
|
|
@@ -21,7 +19,7 @@ module Test
|
|
|
21
19
|
if /\Ain [`'](.+?)'/ =~ context
|
|
22
20
|
method_name = $1
|
|
23
21
|
if /\Ablock (?:\(.+?\) )?in / =~ method_name
|
|
24
|
-
method_name = $
|
|
22
|
+
method_name = $'
|
|
25
23
|
end
|
|
26
24
|
else
|
|
27
25
|
method_name = nil
|
data/lib/test/unit/fixture.rb
CHANGED
|
@@ -50,6 +50,14 @@ module Test
|
|
|
50
50
|
@cached_after_callbacks[type] ||= collect_after_callbacks(type)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def on_ractor_start
|
|
54
|
+
[:setup, :cleanup, :teardown].each do |type|
|
|
55
|
+
before_callbacks(type)
|
|
56
|
+
after_callbacks(type)
|
|
57
|
+
end
|
|
58
|
+
Ractor.make_shareable(self)
|
|
59
|
+
end
|
|
60
|
+
|
|
53
61
|
private
|
|
54
62
|
def target_test_cases
|
|
55
63
|
@cached_target_test_cases ||= collect_target_test_cases
|
|
@@ -136,6 +144,7 @@ module Test
|
|
|
136
144
|
# duplicated because callback_method_name uses callback.object_id.
|
|
137
145
|
# See also: https://github.com/test-unit/test-unit/issues/179
|
|
138
146
|
@callbacks[callback] = true
|
|
147
|
+
callback = Unit.shareable_lambda_if_possible(&callback)
|
|
139
148
|
@test_case.__send__(:define_method, method_name, &callback)
|
|
140
149
|
else
|
|
141
150
|
method_name = method_name_or_callback
|
data/lib/test/unit/omission.rb
CHANGED
|
@@ -142,8 +142,30 @@ module Test
|
|
|
142
142
|
end
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
+
# Omit the rest of the test. This is for Minitest
|
|
146
|
+
# compatibility. Use #omit in new tests.
|
|
147
|
+
#
|
|
148
|
+
# Example:
|
|
149
|
+
#
|
|
150
|
+
# def test_skip
|
|
151
|
+
# skip("Not supported yet")
|
|
152
|
+
# # Not reached here
|
|
153
|
+
# end
|
|
154
|
+
def skip(message=nil, _ignored=nil)
|
|
155
|
+
omit(message || "skipped.")
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Returns whether the test is omitted. This is for Minitest
|
|
159
|
+
# compatibility.
|
|
160
|
+
#
|
|
161
|
+
# @return [Boolean]
|
|
162
|
+
def skipped?
|
|
163
|
+
@internal_data.omitted?
|
|
164
|
+
end
|
|
165
|
+
|
|
145
166
|
private
|
|
146
167
|
def add_omission(omission)
|
|
168
|
+
@internal_data.omitted
|
|
147
169
|
current_result.add_omission(omission)
|
|
148
170
|
end
|
|
149
171
|
end
|
data/lib/test/unit/priority.rb
CHANGED
|
@@ -119,13 +119,14 @@ module Test
|
|
|
119
119
|
File.exist?(passed_file)
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
+
BASE_DIR = File.dirname($0).freeze
|
|
122
123
|
def result_dir
|
|
123
124
|
components = [
|
|
124
125
|
".test-result",
|
|
125
126
|
escape_class_name(@test.class.name || "AnonymousTestCase"),
|
|
126
127
|
escaped_method_name,
|
|
127
128
|
]
|
|
128
|
-
parent_directories = [
|
|
129
|
+
parent_directories = [BASE_DIR, Dir.pwd]
|
|
129
130
|
if Process.respond_to?(:uid)
|
|
130
131
|
parent_directories << File.join(Dir.tmpdir, Process.uid.to_s)
|
|
131
132
|
end
|
|
@@ -28,17 +28,24 @@ remote_ip_port = nil
|
|
|
28
28
|
parser.on("--ip-port=PORT", Integer) do |port|
|
|
29
29
|
remote_ip_port = port
|
|
30
30
|
end
|
|
31
|
+
notify_no_assertions = false
|
|
32
|
+
parser.on("--notify-no-assertions") do
|
|
33
|
+
notify_no_assertions = true
|
|
34
|
+
end
|
|
31
35
|
test_paths = parser.parse!
|
|
32
36
|
$LOAD_PATH.unshift(*load_paths)
|
|
33
37
|
|
|
34
38
|
require_relative "../unit"
|
|
39
|
+
Test::Unit::TestCase.notify_no_assertions = true if notify_no_assertions
|
|
35
40
|
require_relative "collector/load"
|
|
36
41
|
require_relative "process-test-result"
|
|
42
|
+
require_relative "test-finder"
|
|
37
43
|
require_relative "worker-context"
|
|
38
44
|
Test::Unit::AutoRunner.need_auto_run = false
|
|
39
45
|
collector = Test::Unit::Collector::Load.new
|
|
40
46
|
collector.base = base_directory
|
|
41
47
|
suite = collector.collect(*test_paths)
|
|
48
|
+
test_finder = Test::Unit::TestFinder.new(suite)
|
|
42
49
|
|
|
43
50
|
io_open = lambda do |&block|
|
|
44
51
|
if Gem.win_platform?
|
|
@@ -60,9 +67,9 @@ io_open.call do |data_input, data_output|
|
|
|
60
67
|
loop do
|
|
61
68
|
Marshal.dump({status: :ready}, data_output)
|
|
62
69
|
data_output.flush
|
|
63
|
-
test_name = Marshal.load(data_input)
|
|
70
|
+
test_name, test_names = Marshal.load(data_input)
|
|
64
71
|
break if test_name.nil?
|
|
65
|
-
test =
|
|
72
|
+
test = test_finder.find(test_name, test_names)
|
|
66
73
|
result = Test::Unit::ProcessTestResult.new(data_output)
|
|
67
74
|
run_context = Test::Unit::TestRunContext.new(Test::Unit::TestSuiteRunner)
|
|
68
75
|
|
|
@@ -70,7 +77,7 @@ io_open.call do |data_input, data_output|
|
|
|
70
77
|
Marshal.dump({status: :event, event_name: event_name, args: args}, data_output)
|
|
71
78
|
data_output.flush
|
|
72
79
|
end
|
|
73
|
-
if test.
|
|
80
|
+
if test.class.test_suite?
|
|
74
81
|
test_suite = test
|
|
75
82
|
else
|
|
76
83
|
test_suite = Test::Unit::TestSuite.new(test.class.name, test.class)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Tsutomu Katsube.
|
|
4
|
+
# Copyright:: Copyright (c) 2026 Tsutomu Katsube. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
module Test
|
|
8
|
+
module Unit
|
|
9
|
+
class << self
|
|
10
|
+
# @api private
|
|
11
|
+
def ractor_available?
|
|
12
|
+
# The Ractor runner needs Ruby 4.1 or later.
|
|
13
|
+
defined?(Ractor) and
|
|
14
|
+
Ractor.respond_to?(:shareable_lambda) and
|
|
15
|
+
Ractor.method_defined?(:alive?)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @api private
|
|
19
|
+
def non_main_ractor?
|
|
20
|
+
ractor_available? and not Ractor.main?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @api private
|
|
24
|
+
def shareable_lambda(&block)
|
|
25
|
+
if ractor_available?
|
|
26
|
+
Ractor.shareable_lambda(&block)
|
|
27
|
+
else
|
|
28
|
+
block
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @api private
|
|
33
|
+
def shareable_lambda_if_possible(&block)
|
|
34
|
+
if ractor_available?
|
|
35
|
+
begin
|
|
36
|
+
Ractor.shareable_lambda(&block)
|
|
37
|
+
rescue Ractor::IsolationError
|
|
38
|
+
block
|
|
39
|
+
end
|
|
40
|
+
else
|
|
41
|
+
block
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Tsutomu Katsube.
|
|
4
|
+
# Copyright:: Copyright (c) 2026 Tsutomu Katsube. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
module Test
|
|
8
|
+
module Unit
|
|
9
|
+
class RactorTestResult
|
|
10
|
+
class << self
|
|
11
|
+
def test_result?
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(port)
|
|
17
|
+
@port = port
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_run
|
|
21
|
+
send_result(__method__)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_pass
|
|
25
|
+
send_result(__method__)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Records an individual assertion.
|
|
29
|
+
def add_assertion
|
|
30
|
+
send_result(__method__)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def add_error(error)
|
|
34
|
+
send_result(__method__, error)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def add_failure(failure)
|
|
38
|
+
send_result(__method__, failure)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def add_pending(pending)
|
|
42
|
+
send_result(__method__, pending)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def add_omission(omission)
|
|
46
|
+
send_result(__method__, omission)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def add_notification(notification)
|
|
50
|
+
send_result(__method__, notification)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def send_result(action, *args)
|
|
56
|
+
@port.send({status: :result, action: action, args: args})
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Tsutomu Katsube.
|
|
4
|
+
# Copyright:: Copyright (c) 2026 Tsutomu Katsube. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
module Test
|
|
8
|
+
module Unit
|
|
9
|
+
class TestFinder # :nodoc:
|
|
10
|
+
def initialize(test_suite)
|
|
11
|
+
@tests = {}
|
|
12
|
+
add_suite(test_suite)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def find(name, test_names=nil)
|
|
16
|
+
if test_names
|
|
17
|
+
create_test_suite(name, test_names)
|
|
18
|
+
else
|
|
19
|
+
@tests[name]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
def create_test_suite(name, test_names)
|
|
25
|
+
test_suite = TestSuite.new(name, @tests[name].test_case)
|
|
26
|
+
test_names.each do |test_name, sub_test_names|
|
|
27
|
+
test_suite << find(test_name, sub_test_names)
|
|
28
|
+
end
|
|
29
|
+
test_suite
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_suite(test_suite)
|
|
33
|
+
@tests[test_suite.name] ||= test_suite
|
|
34
|
+
test_suite.tests.each do |test|
|
|
35
|
+
if test.class.test_suite?
|
|
36
|
+
add_suite(test)
|
|
37
|
+
else
|
|
38
|
+
@tests[test.name] ||= test
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Tsutomu Katsube.
|
|
4
|
+
# Copyright:: Copyright (c) 2026 Tsutomu Katsube. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
require_relative "test-run-context"
|
|
8
|
+
|
|
9
|
+
module Test
|
|
10
|
+
module Unit
|
|
11
|
+
class TestRactorRunContext < TestRunContext
|
|
12
|
+
attr_reader :test_names
|
|
13
|
+
attr_reader :parallel_unsafe_tests
|
|
14
|
+
attr_accessor :progress_block
|
|
15
|
+
def initialize(runner_class)
|
|
16
|
+
super(runner_class)
|
|
17
|
+
@test_names = []
|
|
18
|
+
@parallel_unsafe_tests = []
|
|
19
|
+
@progress_block = nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -17,8 +17,9 @@ module Test
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def initialize(test_case)
|
|
20
|
+
def initialize(test_case, skip_valid_check: false)
|
|
21
21
|
@test_case = test_case
|
|
22
|
+
@skip_valid_check = skip_valid_check
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def create
|
|
@@ -59,7 +60,7 @@ module Test
|
|
|
59
60
|
def append_test(suite, test_name)
|
|
60
61
|
test = @test_case.new(test_name)
|
|
61
62
|
yield(test) if block_given?
|
|
62
|
-
suite << test if test.valid?
|
|
63
|
+
suite << test if @skip_valid_check or test.valid?
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def collect_test_names
|
|
@@ -67,6 +67,9 @@ module Test
|
|
|
67
67
|
command_line << "--base-directory" << base_directory
|
|
68
68
|
end
|
|
69
69
|
command_line << "--worker-id" << (i + 1).to_s
|
|
70
|
+
if TestCase.notify_no_assertions?
|
|
71
|
+
command_line << "--notify-no-assertions"
|
|
72
|
+
end
|
|
70
73
|
if Gem.win_platform?
|
|
71
74
|
local_address = tcp_server.local_address
|
|
72
75
|
command_line << "--ip-address" << local_address.ip_address
|
|
@@ -189,10 +192,10 @@ module Test
|
|
|
189
192
|
def run_tests_recursive(test_suite, worker_context, &progress_block)
|
|
190
193
|
run_context = worker_context.run_context
|
|
191
194
|
if test_suite.have_fixture?
|
|
192
|
-
run_context.test_names << test_suite.name
|
|
195
|
+
run_context.test_names << [test_suite.name, test_suite.test_names]
|
|
193
196
|
else
|
|
194
197
|
test_suite.tests.each do |test|
|
|
195
|
-
if test.
|
|
198
|
+
if test.class.test_suite?
|
|
196
199
|
run_tests_recursive(test, worker_context, &progress_block)
|
|
197
200
|
else
|
|
198
201
|
run_context.test_names << test.name
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#--
|
|
2
|
+
#
|
|
3
|
+
# Author:: Tsutomu Katsube.
|
|
4
|
+
# Copyright:: Copyright (c) 2026 Tsutomu Katsube. All rights reserved.
|
|
5
|
+
# License:: Ruby license.
|
|
6
|
+
|
|
7
|
+
require_relative "collector/descendant"
|
|
8
|
+
require_relative "ractor-test-result"
|
|
9
|
+
require_relative "test-finder"
|
|
10
|
+
require_relative "test-ractor-run-context"
|
|
11
|
+
require_relative "test-suite-runner"
|
|
12
|
+
|
|
13
|
+
module Test
|
|
14
|
+
module Unit
|
|
15
|
+
class TestSuiteRactorRunner < TestSuiteRunner
|
|
16
|
+
class WorkerData
|
|
17
|
+
attr_reader :id, :base_directory, :producer_port, :test_case_descendants
|
|
18
|
+
def initialize(id, base_directory, producer_port, test_case_descendants)
|
|
19
|
+
@id = id
|
|
20
|
+
@base_directory = base_directory
|
|
21
|
+
@producer_port = producer_port
|
|
22
|
+
@test_case_descendants = test_case_descendants
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Worker
|
|
27
|
+
def initialize(data)
|
|
28
|
+
@data = data
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def send(data)
|
|
32
|
+
@data.producer_port.send(data.merge(consumer_port: Ractor.current.default_port))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def receive
|
|
36
|
+
Ractor.current.default_port.receive
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def run
|
|
40
|
+
collector = Collector::Descendant.new
|
|
41
|
+
suite = collector.collect(@data.base_directory, @data.test_case_descendants)
|
|
42
|
+
test_finder = TestFinder.new(suite)
|
|
43
|
+
|
|
44
|
+
loop do
|
|
45
|
+
send(status: :ready)
|
|
46
|
+
test_name, test_names = receive
|
|
47
|
+
break if test_name.nil?
|
|
48
|
+
test = test_finder.find(test_name, test_names)
|
|
49
|
+
result = RactorTestResult.new(@data.producer_port)
|
|
50
|
+
run_context = TestRunContext.new(TestSuiteRunner)
|
|
51
|
+
|
|
52
|
+
event_listener = lambda do |event_name, *args|
|
|
53
|
+
send(status: :event, event_name: event_name, args: args)
|
|
54
|
+
end
|
|
55
|
+
if test.class.test_suite?
|
|
56
|
+
test_suite = test
|
|
57
|
+
else
|
|
58
|
+
test_suite = TestSuite.new(test.class.name, test.class)
|
|
59
|
+
test_suite << test
|
|
60
|
+
end
|
|
61
|
+
runner = TestSuiteRunner.new(test_suite)
|
|
62
|
+
worker_context = WorkerContext.new(@data.id, run_context, result)
|
|
63
|
+
runner.run(worker_context, &event_listener)
|
|
64
|
+
end
|
|
65
|
+
send(status: :done)
|
|
66
|
+
|
|
67
|
+
receive
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class << self
|
|
72
|
+
def run_all_tests(result, options)
|
|
73
|
+
Assertions.on_ractor_start
|
|
74
|
+
n_workers = TestSuiteRunner.n_workers
|
|
75
|
+
test_suite = options[:test_suite]
|
|
76
|
+
TestCase.on_ractor_start
|
|
77
|
+
TestCase::DESCENDANTS.each do |test_case|
|
|
78
|
+
test_case.on_ractor_start
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
workers = []
|
|
82
|
+
begin
|
|
83
|
+
producer_port = Ractor::Port.new
|
|
84
|
+
n_workers.times do |i|
|
|
85
|
+
worker_data = WorkerData.new(i + 1,
|
|
86
|
+
options[:base_directory],
|
|
87
|
+
producer_port,
|
|
88
|
+
TestCase::DESCENDANTS)
|
|
89
|
+
workers << Ractor.new(worker_data) do |local_worker_data|
|
|
90
|
+
worker = Worker.new(local_worker_data)
|
|
91
|
+
worker.run
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
run_context = TestRactorRunContext.new(self)
|
|
96
|
+
yield(run_context)
|
|
97
|
+
run_context.progress_block.call(TestSuite::STARTED, test_suite.name)
|
|
98
|
+
run_context.progress_block.call(TestSuite::STARTED_OBJECT, test_suite)
|
|
99
|
+
run_context.parallel_unsafe_tests.each(&:call)
|
|
100
|
+
|
|
101
|
+
until run_context.test_names.empty? do
|
|
102
|
+
data = producer_port.receive
|
|
103
|
+
case data[:status]
|
|
104
|
+
when :ready
|
|
105
|
+
test_name = run_context.test_names.shift
|
|
106
|
+
break if test_name.nil?
|
|
107
|
+
data[:consumer_port].send(test_name)
|
|
108
|
+
when :result
|
|
109
|
+
add_result(result, data)
|
|
110
|
+
when :event
|
|
111
|
+
emit_event(options[:event_listener], data)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
workers.each do |worker|
|
|
115
|
+
worker.send(nil)
|
|
116
|
+
end
|
|
117
|
+
n_running_workers = workers.size
|
|
118
|
+
while n_running_workers > 0 do
|
|
119
|
+
data = producer_port.receive
|
|
120
|
+
case data[:status]
|
|
121
|
+
when :result
|
|
122
|
+
add_result(result, data)
|
|
123
|
+
when :event
|
|
124
|
+
emit_event(options[:event_listener], data)
|
|
125
|
+
when :done
|
|
126
|
+
data[:consumer_port].send(nil)
|
|
127
|
+
n_running_workers -= 1
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
ensure
|
|
131
|
+
workers.each(&:join)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
run_context.progress_block.call(TestSuite::FINISHED, test_suite.name)
|
|
135
|
+
run_context.progress_block.call(TestSuite::FINISHED_OBJECT, test_suite)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
private
|
|
139
|
+
def add_result(result, data)
|
|
140
|
+
action = data[:action]
|
|
141
|
+
args = data[:args]
|
|
142
|
+
result.__send__(action, *args)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def emit_event(event_listener, data)
|
|
146
|
+
event_name = data[:event_name]
|
|
147
|
+
args = data[:args]
|
|
148
|
+
event_listener.call(event_name, *args)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def run(worker_context, &progress_block)
|
|
153
|
+
worker_context.run_context.progress_block = progress_block
|
|
154
|
+
run_tests_recursive(@test_suite, worker_context, &progress_block)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
def run_tests_recursive(test_suite, worker_context, &progress_block)
|
|
159
|
+
run_context = worker_context.run_context
|
|
160
|
+
if test_suite.have_fixture?
|
|
161
|
+
if test_suite.parallel_safe_recursive?
|
|
162
|
+
run_context.test_names << [test_suite.name, test_suite.test_names]
|
|
163
|
+
else
|
|
164
|
+
run_context.parallel_unsafe_tests << lambda do
|
|
165
|
+
sub_run_context = TestRunContext.new(TestSuiteRunner)
|
|
166
|
+
sub_worker_context = WorkerContext.new(worker_context.id,
|
|
167
|
+
sub_run_context,
|
|
168
|
+
worker_context.result)
|
|
169
|
+
sub_runner = TestSuiteRunner.new(test_suite)
|
|
170
|
+
sub_runner.run(sub_worker_context, &progress_block)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
else
|
|
174
|
+
test_suite.tests.each do |test|
|
|
175
|
+
if test.class.test_suite?
|
|
176
|
+
run_tests_recursive(test, worker_context, &progress_block)
|
|
177
|
+
elsif test_suite.parallel_safe?
|
|
178
|
+
run_context.test_names << test.name
|
|
179
|
+
else
|
|
180
|
+
run_context.parallel_unsafe_tests << lambda do
|
|
181
|
+
run_test(test, worker_context, &progress_block)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -55,6 +55,8 @@ module Test
|
|
|
55
55
|
test_case.startup
|
|
56
56
|
rescue Exception => e
|
|
57
57
|
raise unless handle_exception(e, worker_context.result)
|
|
58
|
+
ensure
|
|
59
|
+
test_case.worker_id = nil
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
@@ -114,6 +116,8 @@ module Test
|
|
|
114
116
|
test_case.shutdown
|
|
115
117
|
rescue Exception => e
|
|
116
118
|
raise unless handle_exception(e, worker_context.result)
|
|
119
|
+
ensure
|
|
120
|
+
test_case.worker_id = nil
|
|
117
121
|
end
|
|
118
122
|
end
|
|
119
123
|
|
|
@@ -63,17 +63,29 @@ module Test
|
|
|
63
63
|
def run_tests_recursive(test_suite, worker_context, &progress_block)
|
|
64
64
|
run_context = worker_context.run_context
|
|
65
65
|
if test_suite.have_fixture?
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
if test_suite.parallel_safe_recursive?
|
|
67
|
+
task = lambda do |stop_tag, worker_id|
|
|
68
|
+
sub_result = SubTestResult.new(worker_context.result)
|
|
69
|
+
sub_result.stop_tag = stop_tag
|
|
70
|
+
sub_runner = TestSuiteRunner.new(test_suite)
|
|
71
|
+
sub_run_context = TestRunContext.new(TestSuiteRunner)
|
|
72
|
+
sub_worker_context = WorkerContext.new(worker_id, sub_run_context, sub_result)
|
|
73
|
+
sub_runner.run(sub_worker_context, &progress_block)
|
|
74
|
+
end
|
|
75
|
+
run_context.queue << task
|
|
76
|
+
else
|
|
77
|
+
run_context.parallel_unsafe_tests << lambda do
|
|
78
|
+
sub_runner = TestSuiteRunner.new(test_suite)
|
|
79
|
+
sub_run_context = TestRunContext.new(TestSuiteRunner)
|
|
80
|
+
sub_worker_context = WorkerContext.new(worker_context.id,
|
|
81
|
+
sub_run_context,
|
|
82
|
+
worker_context.result)
|
|
83
|
+
sub_runner.run(sub_worker_context, &progress_block)
|
|
84
|
+
end
|
|
72
85
|
end
|
|
73
|
-
run_context.queue << task
|
|
74
86
|
else
|
|
75
87
|
test_suite.tests.each do |test|
|
|
76
|
-
if test.
|
|
88
|
+
if test.class.test_suite?
|
|
77
89
|
run_tests_recursive(test, worker_context, &progress_block)
|
|
78
90
|
elsif test_suite.parallel_safe?
|
|
79
91
|
task = lambda do |stop_tag, worker_id|
|