test-unit 3.7.9 → 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 +59 -0
- data/lib/test/unit/assertions.rb +7 -1
- data/lib/test/unit/attribute.rb +8 -5
- data/lib/test/unit/autorunner.rb +1 -0
- data/lib/test/unit/fault-location-detector.rb +1 -3
- data/lib/test/unit/fixture.rb +9 -0
- data/lib/test/unit/process-worker.rb +4 -2
- data/lib/test/unit/ractor-helper.rb +46 -0
- data/lib/test/unit/ractor-test-result.rb +60 -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-process-runner.rb +1 -1
- 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 +19 -7
- data/lib/test/unit/testcase.rb +41 -18
- data/lib/test/unit/testsuite.rb +10 -7
- data/lib/test/unit/util/backtracefilter.rb +7 -0
- data/lib/test/unit/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15b7580df55aec5b009ea7ce6db96a9200f5b34b1d6becb6737d9229c86507b2
|
|
4
|
+
data.tar.gz: ee9afd7eeba80b6db2a91fbb3b9841065bd4e86eab2806259b51786658c2b62d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8e7c95ff2894200a66dc94c99bc6452e94bdb26f84f7062697f71ff6733c615c1b33cd2b4ac26ec98379cfe8809c1a251bd97ea9bb573e2fa389f38bd56751c
|
|
7
|
+
data.tar.gz: 14f92f0a235ce321f6d8bfe661f654f2192ca90303fb1f9afaf4e1e2e3b5864a143ef79c589d1a1bbd72d4c68fcf414862f0b759ba199cb924341d0e01c4e83a
|
data/doc/text/news.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# News
|
|
2
2
|
|
|
3
|
+
## 3.8.0 - 2026-12-07 {#version-3-8-0}
|
|
4
|
+
|
|
5
|
+
### Improvements
|
|
6
|
+
|
|
7
|
+
* Added support for Ractor based parallel test running. You can use
|
|
8
|
+
it by the `--parallel=ractor` option. You need Ruby 4.1 or later.
|
|
9
|
+
Tests run in non-main Ractors. If the tests pass, the tested code
|
|
10
|
+
works in a non-main Ractor. You can disable parallel test running
|
|
11
|
+
per test case by defining `parallel_safe?` class method that
|
|
12
|
+
returns `false`. The test case runs in the main Ractor.
|
|
13
|
+
* GH-235
|
|
14
|
+
* GH-411
|
|
15
|
+
* GH-414
|
|
16
|
+
* GH-415
|
|
17
|
+
* GH-416
|
|
18
|
+
* GH-417
|
|
19
|
+
* GH-418
|
|
20
|
+
* GH-419
|
|
21
|
+
* GH-420
|
|
22
|
+
* GH-423
|
|
23
|
+
* GH-424
|
|
24
|
+
* GH-425
|
|
25
|
+
* GH-426
|
|
26
|
+
* GH-427
|
|
27
|
+
* GH-428
|
|
28
|
+
* GH-431
|
|
29
|
+
* GH-433
|
|
30
|
+
* GH-434
|
|
31
|
+
* Co authored by Naoto Ono
|
|
32
|
+
|
|
33
|
+
### Fixes
|
|
34
|
+
|
|
35
|
+
* Suppressed method redefined warnings with the
|
|
36
|
+
`--notify-no-assertions` option.
|
|
37
|
+
* GH-427
|
|
38
|
+
|
|
39
|
+
* parallel: thread: Fixed a bug that tests in a sub test case don't
|
|
40
|
+
run when the parent test case has startup/shutdown (test case level
|
|
41
|
+
setup/teardown).
|
|
42
|
+
* GH-429
|
|
43
|
+
* GH-430
|
|
44
|
+
|
|
45
|
+
* parallel: thread: Fixed a bug that `parallel_safe?` is ignored
|
|
46
|
+
when the test case has startup/shutdown.
|
|
47
|
+
* GH-432
|
|
48
|
+
|
|
49
|
+
* parallel: process: Fixed a bug that filters such as the `-n`
|
|
50
|
+
option are ignored when the test case has startup/shutdown.
|
|
51
|
+
* GH-434
|
|
52
|
+
|
|
53
|
+
* parallel: process: Fixed a bug that tests declared with
|
|
54
|
+
`Test::Unit::TestCase.ractor` don't run when the test case has
|
|
55
|
+
startup/shutdown.
|
|
56
|
+
* GH-434
|
|
57
|
+
|
|
58
|
+
### Thanks
|
|
59
|
+
|
|
60
|
+
* Naoto Ono
|
|
61
|
+
|
|
3
62
|
## 3.7.9 - 2026-11-24 {#version-3-7-9}
|
|
4
63
|
|
|
5
64
|
### Improvements
|
data/lib/test/unit/assertions.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Copyright (c) 2009-2013 Kouhei Sutou. All rights reserved.
|
|
4
4
|
# License:: Ruby license.
|
|
5
5
|
|
|
6
|
+
require_relative 'ractor-helper'
|
|
6
7
|
require_relative 'assertion-failed-error'
|
|
7
8
|
require_relative 'util/backtracefilter'
|
|
8
9
|
require_relative 'util/memory-usage'
|
|
@@ -36,6 +37,11 @@ module Test
|
|
|
36
37
|
# end
|
|
37
38
|
|
|
38
39
|
module Assertions
|
|
40
|
+
class << self
|
|
41
|
+
def on_ractor_start
|
|
42
|
+
Ractor.make_shareable(AssertionMessage::Inspector.inspector_classes)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
39
45
|
|
|
40
46
|
##
|
|
41
47
|
# The assertion upon which all other assertions are based. Passes if the
|
|
@@ -131,7 +137,7 @@ module Test
|
|
|
131
137
|
have_object = !NOT_SPECIFIED.equal?(object)
|
|
132
138
|
if block
|
|
133
139
|
message = object if have_object
|
|
134
|
-
if defined?(PowerAssert)
|
|
140
|
+
if defined?(PowerAssert) and not Unit.non_main_ractor?
|
|
135
141
|
PowerAssert.start(block, :assertion_method => __callee__) do |pa|
|
|
136
142
|
pa_message = AssertionMessage.delayed_literal(&pa.message_proc)
|
|
137
143
|
assertion_message = build_message(message, "?", pa_message)
|
data/lib/test/unit/attribute.rb
CHANGED
|
@@ -183,8 +183,7 @@ module Test
|
|
|
183
183
|
recursive_p = options[:recursive]
|
|
184
184
|
recursive_p = true if recursive_p.nil?
|
|
185
185
|
|
|
186
|
-
@attributes_table
|
|
187
|
-
if @attributes_table.key?(method_name)
|
|
186
|
+
if defined?(@attributes_table) and @attributes_table.key?(method_name)
|
|
188
187
|
attributes = @attributes_table[method_name]
|
|
189
188
|
if attributes.key?(name)
|
|
190
189
|
return attributes[name]
|
|
@@ -194,14 +193,18 @@ module Test
|
|
|
194
193
|
return nil unless recursive_p
|
|
195
194
|
return nil if self == TestCase
|
|
196
195
|
|
|
196
|
+
parent_test_case = find_parent_test_case
|
|
197
|
+
return nil if parent_test_case.nil?
|
|
198
|
+
|
|
199
|
+
parent_test_case.find_attribute(method_name, name, options)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def find_parent_test_case # :nodoc:
|
|
197
203
|
@cached_parent_test_case ||= ancestors.find do |ancestor|
|
|
198
204
|
ancestor != self and
|
|
199
205
|
ancestor.is_a?(Class) and
|
|
200
206
|
ancestor < Test::Unit::Attribute
|
|
201
207
|
end
|
|
202
|
-
return nil if @cached_parent_test_case.nil?
|
|
203
|
-
|
|
204
|
-
@cached_parent_test_case.find_attribute(method_name, name, options)
|
|
205
208
|
end
|
|
206
209
|
|
|
207
210
|
@@attribute_observers = StringifyKeyHash.new
|
data/lib/test/unit/autorunner.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
|
|
@@ -39,11 +39,13 @@ require_relative "../unit"
|
|
|
39
39
|
Test::Unit::TestCase.notify_no_assertions = true if notify_no_assertions
|
|
40
40
|
require_relative "collector/load"
|
|
41
41
|
require_relative "process-test-result"
|
|
42
|
+
require_relative "test-finder"
|
|
42
43
|
require_relative "worker-context"
|
|
43
44
|
Test::Unit::AutoRunner.need_auto_run = false
|
|
44
45
|
collector = Test::Unit::Collector::Load.new
|
|
45
46
|
collector.base = base_directory
|
|
46
47
|
suite = collector.collect(*test_paths)
|
|
48
|
+
test_finder = Test::Unit::TestFinder.new(suite)
|
|
47
49
|
|
|
48
50
|
io_open = lambda do |&block|
|
|
49
51
|
if Gem.win_platform?
|
|
@@ -65,9 +67,9 @@ io_open.call do |data_input, data_output|
|
|
|
65
67
|
loop do
|
|
66
68
|
Marshal.dump({status: :ready}, data_output)
|
|
67
69
|
data_output.flush
|
|
68
|
-
test_name = Marshal.load(data_input)
|
|
70
|
+
test_name, test_names = Marshal.load(data_input)
|
|
69
71
|
break if test_name.nil?
|
|
70
|
-
test =
|
|
72
|
+
test = test_finder.find(test_name, test_names)
|
|
71
73
|
result = Test::Unit::ProcessTestResult.new(data_output)
|
|
72
74
|
run_context = Test::Unit::TestRunContext.new(Test::Unit::TestSuiteRunner)
|
|
73
75
|
|
|
@@ -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
|
|
@@ -192,7 +192,7 @@ module Test
|
|
|
192
192
|
def run_tests_recursive(test_suite, worker_context, &progress_block)
|
|
193
193
|
run_context = worker_context.run_context
|
|
194
194
|
if test_suite.have_fixture?
|
|
195
|
-
run_context.test_names << test_suite.name
|
|
195
|
+
run_context.test_names << [test_suite.name, test_suite.test_names]
|
|
196
196
|
else
|
|
197
197
|
test_suite.tests.each do |test|
|
|
198
198
|
if test.class.test_suite?
|
|
@@ -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,14 +63,26 @@ 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
88
|
if test.class.test_suite?
|
data/lib/test/unit/testcase.rb
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# * Copyright (c) 2008-2012 Kouhei Sutou <tt><kou@clear-code.com></tt>
|
|
7
7
|
# License:: Ruby license.
|
|
8
8
|
|
|
9
|
+
require_relative 'ractor-helper'
|
|
9
10
|
require_relative 'attribute'
|
|
10
11
|
require_relative 'fixture'
|
|
11
12
|
require_relative 'exception-handler'
|
|
@@ -180,9 +181,8 @@ module Test
|
|
|
180
181
|
#
|
|
181
182
|
# @since 3.7.9
|
|
182
183
|
def notify_no_assertions=(boolean)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
end
|
|
184
|
+
redefine_singleton_method(:notify_no_assertions?,
|
|
185
|
+
&Unit.shareable_lambda {boolean})
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
def test_suite?
|
|
@@ -193,8 +193,17 @@ module Test
|
|
|
193
193
|
true
|
|
194
194
|
end
|
|
195
195
|
|
|
196
|
+
def on_ractor_start
|
|
197
|
+
Util::BacktraceFilter.on_ractor_start
|
|
198
|
+
Ractor.make_shareable(ExceptionHandler.exception_handlers)
|
|
199
|
+
Ractor.make_shareable(@added_method_names)
|
|
200
|
+
Ractor.make_shareable(@attributes_table)
|
|
201
|
+
find_parent_test_case
|
|
202
|
+
fixture.on_ractor_start
|
|
203
|
+
end
|
|
204
|
+
|
|
196
205
|
def inherited(sub_class) # :nodoc:
|
|
197
|
-
DESCENDANTS << sub_class
|
|
206
|
+
DESCENDANTS << sub_class unless Unit.non_main_ractor?
|
|
198
207
|
super
|
|
199
208
|
end
|
|
200
209
|
|
|
@@ -208,10 +217,10 @@ module Test
|
|
|
208
217
|
result
|
|
209
218
|
end
|
|
210
219
|
|
|
211
|
-
@@added_method_names = {}
|
|
212
220
|
def method_added(name) # :nodoc:
|
|
213
221
|
super
|
|
214
|
-
|
|
222
|
+
return if Unit.non_main_ractor?
|
|
223
|
+
added_method_names = (@added_method_names ||= {})
|
|
215
224
|
stringified_name = name.to_s
|
|
216
225
|
if added_method_names.key?(stringified_name)
|
|
217
226
|
attribute(:redefined, {:backtrace => caller}, {}, stringified_name)
|
|
@@ -239,7 +248,7 @@ module Test
|
|
|
239
248
|
end
|
|
240
249
|
|
|
241
250
|
def added_method_names # :nodoc:
|
|
242
|
-
(
|
|
251
|
+
(@added_method_names ||= {}).keys
|
|
243
252
|
end
|
|
244
253
|
|
|
245
254
|
# Rolls up all of the test* methods in the fixture into
|
|
@@ -327,15 +336,9 @@ module Test
|
|
|
327
336
|
def shutdown
|
|
328
337
|
end
|
|
329
338
|
|
|
330
|
-
@@test_orders = {}
|
|
331
|
-
|
|
332
339
|
# Returns the current test order. This returns
|
|
333
340
|
# `:alphabetic` by default.
|
|
334
341
|
def test_order
|
|
335
|
-
ancestors.each do |ancestor|
|
|
336
|
-
order = @@test_orders[ancestor]
|
|
337
|
-
return order if order
|
|
338
|
-
end
|
|
339
342
|
AVAILABLE_ORDERS.first
|
|
340
343
|
end
|
|
341
344
|
|
|
@@ -352,7 +355,7 @@ module Test
|
|
|
352
355
|
# :defined
|
|
353
356
|
# : Tests are sorted in defined order.
|
|
354
357
|
def test_order=(order)
|
|
355
|
-
|
|
358
|
+
redefine_singleton_method(:test_order, &Unit.shareable_lambda {order})
|
|
356
359
|
end
|
|
357
360
|
|
|
358
361
|
# Defines a test in declarative syntax or marks
|
|
@@ -394,6 +397,7 @@ module Test
|
|
|
394
397
|
if block.respond_to?(:source_location)
|
|
395
398
|
attribute(:source_location, block.source_location, {}, method_name)
|
|
396
399
|
end
|
|
400
|
+
block = Unit.shareable_lambda_if_possible(&block)
|
|
397
401
|
define_method(method_name, &block)
|
|
398
402
|
else
|
|
399
403
|
targets = test_description_or_targets
|
|
@@ -555,11 +559,19 @@ module Test
|
|
|
555
559
|
#
|
|
556
560
|
# @since 3.7.4
|
|
557
561
|
def worker_id
|
|
558
|
-
|
|
562
|
+
if Unit.non_main_ractor?
|
|
563
|
+
Ractor[:test_unit_worker_id] || 0
|
|
564
|
+
else
|
|
565
|
+
@worker_id || 0
|
|
566
|
+
end
|
|
559
567
|
end
|
|
560
568
|
|
|
561
569
|
def worker_id=(worker_id) # :nodoc:
|
|
562
|
-
|
|
570
|
+
if Unit.non_main_ractor?
|
|
571
|
+
Ractor[:test_unit_worker_id] = worker_id
|
|
572
|
+
else
|
|
573
|
+
@worker_id = worker_id
|
|
574
|
+
end
|
|
563
575
|
end
|
|
564
576
|
|
|
565
577
|
private
|
|
@@ -609,9 +621,11 @@ module Test
|
|
|
609
621
|
parent_test_case = self
|
|
610
622
|
sub_test_case = Class.new(self) do
|
|
611
623
|
singleton_class = class << self; self; end
|
|
612
|
-
|
|
613
|
-
|
|
624
|
+
full_name = [parent_test_case.name, name].compact.join("::").freeze
|
|
625
|
+
name_method = Unit.shareable_lambda do
|
|
626
|
+
full_name
|
|
614
627
|
end
|
|
628
|
+
singleton_class.__send__(:define_method, :name, &name_method)
|
|
615
629
|
end
|
|
616
630
|
# Give the anonymous class a unique, Base64 encoded constant
|
|
617
631
|
# name. So it becomes a named class that `Marshal` can
|
|
@@ -622,6 +636,15 @@ module Test
|
|
|
622
636
|
const_set(:"TEST_#{encoded_name}", sub_test_case)
|
|
623
637
|
sub_test_case
|
|
624
638
|
end
|
|
639
|
+
|
|
640
|
+
# @private
|
|
641
|
+
def redefine_singleton_method(name, &block)
|
|
642
|
+
# Ruby warns if we define a method again without removing it.
|
|
643
|
+
if singleton_methods(false).include?(name)
|
|
644
|
+
singleton_class.__send__(:remove_method, name)
|
|
645
|
+
end
|
|
646
|
+
define_singleton_method(name, &block)
|
|
647
|
+
end
|
|
625
648
|
end
|
|
626
649
|
|
|
627
650
|
attr_reader :method_name
|
data/lib/test/unit/testsuite.rb
CHANGED
|
@@ -50,17 +50,14 @@ module Test
|
|
|
50
50
|
@elapsed_time = nil
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
@tests.each do |test|
|
|
53
|
+
def test_names
|
|
54
|
+
@tests.collect do |test|
|
|
56
55
|
if test.class.test_suite?
|
|
57
|
-
|
|
58
|
-
return t if t
|
|
56
|
+
[test.name, test.test_names]
|
|
59
57
|
else
|
|
60
|
-
|
|
58
|
+
test.name
|
|
61
59
|
end
|
|
62
60
|
end
|
|
63
|
-
nil
|
|
64
61
|
end
|
|
65
62
|
|
|
66
63
|
def parallel_safe?
|
|
@@ -68,6 +65,12 @@ module Test
|
|
|
68
65
|
@test_case.parallel_safe?
|
|
69
66
|
end
|
|
70
67
|
|
|
68
|
+
def parallel_safe_recursive?
|
|
69
|
+
return false unless parallel_safe?
|
|
70
|
+
sub_test_suites = @tests.select {|test| test.class.test_suite?}
|
|
71
|
+
sub_test_suites.all? {|test_suite| test_suite.parallel_safe_recursive?}
|
|
72
|
+
end
|
|
73
|
+
|
|
71
74
|
def have_fixture?
|
|
72
75
|
return false if @test_case.nil?
|
|
73
76
|
return true if @test_case.method(:startup).owner != TestCase.singleton_class
|
|
@@ -22,6 +22,13 @@ module Test
|
|
|
22
22
|
::PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] :
|
|
23
23
|
nil
|
|
24
24
|
|
|
25
|
+
class << self
|
|
26
|
+
def on_ractor_start
|
|
27
|
+
Ractor.make_shareable(TESTUNIT_PREFIX)
|
|
28
|
+
Ractor.make_shareable(POWERASSERT_PREFIX)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
25
32
|
module_function
|
|
26
33
|
def filter_backtrace(backtrace, prefix=nil)
|
|
27
34
|
return ["No backtrace"] unless backtrace
|
data/lib/test/unit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: test-unit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kouhei Sutou
|
|
@@ -77,14 +77,19 @@ files:
|
|
|
77
77
|
- lib/test/unit/priority.rb
|
|
78
78
|
- lib/test/unit/process-test-result.rb
|
|
79
79
|
- lib/test/unit/process-worker.rb
|
|
80
|
+
- lib/test/unit/ractor-helper.rb
|
|
81
|
+
- lib/test/unit/ractor-test-result.rb
|
|
80
82
|
- lib/test/unit/runner/console.rb
|
|
81
83
|
- lib/test/unit/runner/emacs.rb
|
|
82
84
|
- lib/test/unit/runner/xml.rb
|
|
83
85
|
- lib/test/unit/sub-test-result.rb
|
|
86
|
+
- lib/test/unit/test-finder.rb
|
|
84
87
|
- lib/test/unit/test-process-run-context.rb
|
|
88
|
+
- lib/test/unit/test-ractor-run-context.rb
|
|
85
89
|
- lib/test/unit/test-run-context.rb
|
|
86
90
|
- lib/test/unit/test-suite-creator.rb
|
|
87
91
|
- lib/test/unit/test-suite-process-runner.rb
|
|
92
|
+
- lib/test/unit/test-suite-ractor-runner.rb
|
|
88
93
|
- lib/test/unit/test-suite-runner.rb
|
|
89
94
|
- lib/test/unit/test-suite-thread-runner.rb
|
|
90
95
|
- lib/test/unit/test-thread-run-context.rb
|