mutant 0.8.24 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/Changelog.md +14 -654
- data/Gemfile +13 -0
- data/Gemfile.lock +59 -64
- data/LICENSE +271 -20
- data/README.md +73 -140
- data/Rakefile +0 -21
- data/bin/mutant +7 -2
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +5 -9
- data/docs/incremental.md +76 -0
- data/docs/known-problems.md +0 -14
- data/docs/mutant-minitest.md +1 -1
- data/docs/mutant-rspec.md +2 -24
- data/lib/mutant.rb +45 -53
- data/lib/mutant/ast/nodes.rb +0 -2
- data/lib/mutant/ast/types.rb +1 -117
- data/lib/mutant/base.rb +192 -0
- data/lib/mutant/bootstrap.rb +145 -0
- data/lib/mutant/cli.rb +68 -54
- data/lib/mutant/config.rb +119 -6
- data/lib/mutant/env.rb +94 -8
- data/lib/mutant/expression.rb +6 -1
- data/lib/mutant/expression/parser.rb +9 -31
- data/lib/mutant/integration.rb +64 -36
- data/lib/mutant/isolation.rb +16 -1
- data/lib/mutant/isolation/fork.rb +105 -40
- data/lib/mutant/license.rb +34 -0
- data/lib/mutant/license/subscription.rb +47 -0
- data/lib/mutant/license/subscription/commercial.rb +57 -0
- data/lib/mutant/license/subscription/opensource.rb +77 -0
- data/lib/mutant/loader.rb +27 -4
- data/lib/mutant/matcher.rb +48 -1
- data/lib/mutant/matcher/chain.rb +1 -1
- data/lib/mutant/matcher/config.rb +0 -2
- data/lib/mutant/matcher/filter.rb +1 -1
- data/lib/mutant/matcher/method.rb +11 -7
- data/lib/mutant/matcher/methods.rb +1 -1
- data/lib/mutant/matcher/namespace.rb +1 -1
- data/lib/mutant/matcher/null.rb +1 -1
- data/lib/mutant/matcher/scope.rb +1 -1
- data/lib/mutant/meta/example/dsl.rb +0 -8
- data/lib/mutant/mutation.rb +1 -2
- data/lib/mutant/mutator/node.rb +2 -9
- data/lib/mutant/mutator/node/arguments.rb +1 -1
- data/lib/mutant/mutator/node/class.rb +0 -8
- data/lib/mutant/mutator/node/define.rb +0 -12
- data/lib/mutant/mutator/node/generic.rb +30 -44
- data/lib/mutant/mutator/node/index.rb +4 -4
- data/lib/mutant/mutator/node/literal/regex.rb +0 -39
- data/lib/mutant/mutator/node/send.rb +13 -12
- data/lib/mutant/parallel.rb +61 -40
- data/lib/mutant/parallel/driver.rb +59 -0
- data/lib/mutant/parallel/source.rb +6 -2
- data/lib/mutant/parallel/worker.rb +63 -45
- data/lib/mutant/range.rb +15 -0
- data/lib/mutant/reporter/cli.rb +5 -11
- data/lib/mutant/reporter/cli/format.rb +3 -46
- data/lib/mutant/reporter/cli/printer/config.rb +5 -6
- data/lib/mutant/reporter/cli/printer/env.rb +40 -0
- data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
- data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
- data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
- data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
- data/lib/mutant/repository.rb +0 -65
- data/lib/mutant/repository/diff.rb +104 -0
- data/lib/mutant/repository/diff/ranges.rb +52 -0
- data/lib/mutant/result.rb +16 -7
- data/lib/mutant/runner.rb +38 -47
- data/lib/mutant/runner/sink.rb +1 -1
- data/lib/mutant/selector/null.rb +19 -0
- data/lib/mutant/subject.rb +3 -1
- data/lib/mutant/subject/method/instance.rb +3 -1
- data/lib/mutant/transform.rb +511 -0
- data/lib/mutant/variable.rb +282 -0
- data/lib/mutant/version.rb +1 -1
- data/lib/mutant/warnings.rb +113 -0
- data/meta/case.rb +1 -0
- data/meta/class.rb +0 -9
- data/meta/def.rb +1 -26
- data/meta/regexp.rb +10 -20
- data/meta/send.rb +14 -46
- data/mutant-minitest.gemspec +1 -1
- data/mutant-rspec.gemspec +2 -2
- data/mutant.gemspec +15 -16
- data/mutant.yml +6 -0
- data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
- data/spec/integration/mutant/minitest_spec.rb +3 -2
- data/spec/integration/mutant/rspec_spec.rb +4 -3
- data/spec/integrations.yml +16 -13
- data/spec/shared/base_behavior.rb +45 -0
- data/spec/shared/framework_integration_behavior.rb +43 -14
- data/spec/spec_helper.rb +21 -17
- data/spec/support/corpus.rb +56 -95
- data/spec/support/shared_context.rb +37 -14
- data/spec/support/xspec.rb +7 -3
- data/spec/unit/mutant/bootstrap_spec.rb +216 -0
- data/spec/unit/mutant/cli_spec.rb +173 -117
- data/spec/unit/mutant/config_spec.rb +126 -0
- data/spec/unit/mutant/either_spec.rb +247 -0
- data/spec/unit/mutant/env_spec.rb +162 -40
- data/spec/unit/mutant/expression/method_spec.rb +16 -0
- data/spec/unit/mutant/expression/parser_spec.rb +29 -33
- data/spec/unit/mutant/expression_spec.rb +5 -7
- data/spec/unit/mutant/integration_spec.rb +100 -9
- data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
- data/spec/unit/mutant/isolation/result_spec.rb +33 -1
- data/spec/unit/mutant/license_spec.rb +257 -0
- data/spec/unit/mutant/loader_spec.rb +50 -11
- data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
- data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
- data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
- data/spec/unit/mutant/matcher_spec.rb +102 -0
- data/spec/unit/mutant/maybe_spec.rb +60 -0
- data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
- data/spec/unit/mutant/mutation_spec.rb +13 -6
- data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
- data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
- data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
- data/spec/unit/mutant/parallel_spec.rb +105 -8
- data/spec/unit/mutant/range_spec.rb +141 -0
- data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
- data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
- data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
- data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
- data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
- data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
- data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
- data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
- data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
- data/spec/unit/mutant/repository/diff_spec.rb +84 -71
- data/spec/unit/mutant/require_highjack_spec.rb +1 -1
- data/spec/unit/mutant/result/env_spec.rb +39 -9
- data/spec/unit/mutant/result/test_spec.rb +14 -0
- data/spec/unit/mutant/runner_spec.rb +88 -41
- data/spec/unit/mutant/selector/expression_spec.rb +11 -10
- data/spec/unit/mutant/selector/null_spec.rb +17 -0
- data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
- data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
- data/spec/unit/mutant/subject_spec.rb +9 -1
- data/spec/unit/mutant/transform/array_spec.rb +92 -0
- data/spec/unit/mutant/transform/bool_spec.rb +63 -0
- data/spec/unit/mutant/transform/error_spec.rb +132 -0
- data/spec/unit/mutant/transform/exception_spec.rb +44 -0
- data/spec/unit/mutant/transform/hash_spec.rb +236 -0
- data/spec/unit/mutant/transform/index_spec.rb +92 -0
- data/spec/unit/mutant/transform/named_spec.rb +49 -0
- data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
- data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
- data/spec/unit/mutant/variable_spec.rb +618 -0
- data/spec/unit/mutant/warnings_spec.rb +89 -0
- data/spec/unit/mutant/world_spec.rb +63 -0
- data/test_app/Gemfile.minitest +0 -2
- metadata +79 -113
- data/.gitattributes +0 -1
- data/.ruby-gemset +0 -1
- data/config/triage.yml +0 -2
- data/lib/mutant/actor.rb +0 -57
- data/lib/mutant/actor/env.rb +0 -31
- data/lib/mutant/actor/mailbox.rb +0 -34
- data/lib/mutant/actor/receiver.rb +0 -42
- data/lib/mutant/actor/sender.rb +0 -26
- data/lib/mutant/ast/meta/restarg.rb +0 -19
- data/lib/mutant/ast/regexp.rb +0 -42
- data/lib/mutant/ast/regexp/transformer.rb +0 -187
- data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
- data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
- data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
- data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
- data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
- data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
- data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
- data/lib/mutant/env/bootstrap.rb +0 -160
- data/lib/mutant/matcher/compiler.rb +0 -60
- data/lib/mutant/mutator/node/regexp.rb +0 -35
- data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
- data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
- data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
- data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
- data/lib/mutant/parallel/master.rb +0 -181
- data/lib/mutant/reporter/cli/printer/status.rb +0 -53
- data/lib/mutant/reporter/cli/tput.rb +0 -46
- data/lib/mutant/warning_filter.rb +0 -61
- data/meta/regexp/character_types.rb +0 -23
- data/meta/regexp/regexp_alternation_meta.rb +0 -13
- data/meta/regexp/regexp_bol_anchor.rb +0 -10
- data/meta/regexp/regexp_bos_anchor.rb +0 -18
- data/meta/regexp/regexp_capture_group.rb +0 -19
- data/meta/regexp/regexp_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_eos_anchor.rb +0 -8
- data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
- data/meta/regexp/regexp_root_expression.rb +0 -10
- data/meta/restarg.rb +0 -10
- data/spec/support/fake_actor.rb +0 -111
- data/spec/support/warning.rb +0 -66
- data/spec/unit/mutant/actor/binding_spec.rb +0 -34
- data/spec/unit/mutant/actor/env_spec.rb +0 -31
- data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
- data/spec/unit/mutant/actor/message_spec.rb +0 -25
- data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
- data/spec/unit/mutant/actor/sender_spec.rb +0 -24
- data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
- data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
- data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
- data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
- data/spec/unit/mutant/parallel/master_spec.rb +0 -338
- data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
- data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
- data/spec/unit/mutant/warning_filter_spec.rb +0 -106
- data/spec/unit/mutant_spec.rb +0 -17
- data/test_app/Gemfile.rspec3.7 +0 -7
@@ -1,188 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This spec is a good example for:
|
4
|
-
#
|
5
|
-
# If test look that ugly the class under test sucks.
|
6
|
-
#
|
7
|
-
# As the bootstrap needs to infect global VM state
|
8
|
-
# this is to some degree acceptable.
|
9
|
-
#
|
10
|
-
# Still the bootstrap needs to be cleaned up.
|
11
|
-
# And the change that added this warning did the groundwork.
|
12
|
-
RSpec.describe Mutant::Env::Bootstrap do
|
13
|
-
let(:matcher_config) { Mutant::Matcher::Config::DEFAULT }
|
14
|
-
let(:integration) { instance_double(Mutant::Integration) }
|
15
|
-
let(:integration_class) { instance_double(Class) }
|
16
|
-
let(:object_space_modules) { [] }
|
17
|
-
|
18
|
-
let(:config) do
|
19
|
-
Mutant::Config::DEFAULT.with(
|
20
|
-
includes: [],
|
21
|
-
integration: integration_class,
|
22
|
-
jobs: 1,
|
23
|
-
matcher: matcher_config,
|
24
|
-
reporter: instance_double(Mutant::Reporter),
|
25
|
-
requires: []
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:expected_env) do
|
30
|
-
Mutant::Env.new(
|
31
|
-
actor_env: Mutant::Actor::Env.new(Thread),
|
32
|
-
config: config,
|
33
|
-
integration: integration,
|
34
|
-
matchable_scopes: [],
|
35
|
-
mutations: [],
|
36
|
-
parser: Mutant::Parser.new,
|
37
|
-
selector: Mutant::Selector::Expression.new(integration),
|
38
|
-
subjects: []
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
shared_examples_for 'bootstrap call' do
|
43
|
-
it { should eql(expected_env) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def expect_warning
|
47
|
-
expect(config.reporter).to receive(:warn)
|
48
|
-
.with(expected_warning)
|
49
|
-
.and_return(config.reporter)
|
50
|
-
end
|
51
|
-
|
52
|
-
before do
|
53
|
-
expect(integration_class).to receive(:new)
|
54
|
-
.with(config)
|
55
|
-
.and_return(integration)
|
56
|
-
|
57
|
-
expect(integration).to receive_messages(setup: integration)
|
58
|
-
|
59
|
-
expect(ObjectSpace).to receive(:each_object)
|
60
|
-
.with(Module)
|
61
|
-
.and_return(object_space_modules.each)
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#warn' do
|
65
|
-
let(:object) { described_class.new(config) }
|
66
|
-
let(:expected_warning) { instance_double(String) }
|
67
|
-
|
68
|
-
subject { object.warn(expected_warning) }
|
69
|
-
|
70
|
-
before { expect_warning }
|
71
|
-
|
72
|
-
it_behaves_like 'a command method'
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '.call' do
|
76
|
-
subject { described_class.call(config) }
|
77
|
-
|
78
|
-
context 'when Module#name calls result in exceptions' do
|
79
|
-
let(:object_space_modules) { [invalid_class] }
|
80
|
-
|
81
|
-
let(:expected_warning) do
|
82
|
-
"Class#name from: #{invalid_class} raised an error: " \
|
83
|
-
"RuntimeError. #{Mutant::Env::SEMANTICS_MESSAGE}"
|
84
|
-
end
|
85
|
-
|
86
|
-
let(:invalid_class) do
|
87
|
-
Class.new do
|
88
|
-
def self.name
|
89
|
-
fail
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
after do
|
95
|
-
# Fix Class#name so other specs do not see this one
|
96
|
-
class << invalid_class
|
97
|
-
undef :name
|
98
|
-
def name; end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
before { expect_warning }
|
103
|
-
|
104
|
-
include_examples 'bootstrap call'
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'when requires are configured' do
|
108
|
-
let(:config) { super().with(requires: %w[foo bar]) }
|
109
|
-
|
110
|
-
before do
|
111
|
-
%w[foo bar].each do |component|
|
112
|
-
expect(Kernel).to receive(:require)
|
113
|
-
.with(component)
|
114
|
-
.and_return(true)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
include_examples 'bootstrap call'
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'when includes are configured' do
|
122
|
-
let(:config) { super().with(includes: %w[foo bar]) }
|
123
|
-
|
124
|
-
before do
|
125
|
-
%w[foo bar].each do |component|
|
126
|
-
expect($LOAD_PATH).to receive(:<<)
|
127
|
-
.with(component)
|
128
|
-
.and_return($LOAD_PATH)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
include_examples 'bootstrap call'
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'when Module#name does not return a String or nil' do
|
136
|
-
let(:object_space_modules) { [invalid_class] }
|
137
|
-
|
138
|
-
let(:invalid_class) do
|
139
|
-
Class.new do
|
140
|
-
def self.name
|
141
|
-
Object
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
let(:expected_warning) do
|
147
|
-
"Class#name from: #{invalid_class} " \
|
148
|
-
"returned Object. #{Mutant::Env::SEMANTICS_MESSAGE}"
|
149
|
-
end
|
150
|
-
|
151
|
-
after do
|
152
|
-
# Fix Class#name so other specs do not see this one
|
153
|
-
class << invalid_class
|
154
|
-
undef :name
|
155
|
-
def name; end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
before { expect_warning }
|
160
|
-
|
161
|
-
include_examples 'bootstrap call'
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'when scope matches expression' do
|
165
|
-
let(:object_space_modules) { [TestApp::Literal, TestApp::Empty] }
|
166
|
-
let(:match_expressions) { object_space_modules.map(&:name).map(&method(:parse_expression)) }
|
167
|
-
|
168
|
-
let(:matcher_config) do
|
169
|
-
super().with(match_expressions: match_expressions)
|
170
|
-
end
|
171
|
-
|
172
|
-
let(:expected_env) do
|
173
|
-
subjects = Mutant::Matcher::Scope.new(TestApp::Literal).call(Fixtures::TEST_ENV)
|
174
|
-
|
175
|
-
super().with(
|
176
|
-
matchable_scopes: [
|
177
|
-
Mutant::Scope.new(TestApp::Empty, match_expressions.last),
|
178
|
-
Mutant::Scope.new(TestApp::Literal, match_expressions.first)
|
179
|
-
],
|
180
|
-
mutations: subjects.flat_map(&:mutations),
|
181
|
-
subjects: subjects
|
182
|
-
)
|
183
|
-
end
|
184
|
-
|
185
|
-
include_examples 'bootstrap call'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Matcher::Compiler::SubjectPrefix, '#call' do
|
4
|
-
let(:object) { described_class.new(parse_expression('Foo*')) }
|
5
|
-
|
6
|
-
let(:_subject) do
|
7
|
-
instance_double(
|
8
|
-
Mutant::Subject,
|
9
|
-
expression: parse_expression(subject_expression)
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
subject { object.call(_subject) }
|
14
|
-
|
15
|
-
context 'when subject expression is prefixed by expression' do
|
16
|
-
let(:subject_expression) { 'Foo::Bar' }
|
17
|
-
|
18
|
-
it { should be(true) }
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when subject expression is NOT prefixed by expression' do
|
22
|
-
let(:subject_expression) { 'Bar' }
|
23
|
-
|
24
|
-
it { should be(false) }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,338 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Mutant::Parallel::Master do
|
4
|
-
let(:message_sequence) { FakeActor::MessageSequence.new }
|
5
|
-
let(:actor_names) { %i[master worker_a worker_b] }
|
6
|
-
let(:sink) { FakeSink.new }
|
7
|
-
let(:processor) { instance_double(Proc) }
|
8
|
-
let(:worker_a) { actor_env.mailbox(:worker_a).sender }
|
9
|
-
let(:worker_b) { actor_env.mailbox(:worker_b).sender }
|
10
|
-
let(:parent) { actor_env.mailbox(:parent).sender }
|
11
|
-
let(:job_payload_a) { instance_double(Object) }
|
12
|
-
let(:job_payload_b) { instance_double(Object) }
|
13
|
-
let(:job_result_payload_a) { instance_double(Object) }
|
14
|
-
let(:job_result_payload_b) { instance_double(Object) }
|
15
|
-
let(:job_a) { Mutant::Parallel::Job.new(index: 0, payload: job_payload_a) }
|
16
|
-
let(:job_b) { Mutant::Parallel::Job.new(index: 1, payload: job_payload_b) }
|
17
|
-
let(:job_result_a) { Mutant::Parallel::JobResult.new(job: job_a, payload: job_result_payload_a) }
|
18
|
-
let(:job_result_b) { Mutant::Parallel::JobResult.new(job: job_b, payload: job_result_payload_b) }
|
19
|
-
|
20
|
-
let(:actor_env) do
|
21
|
-
FakeActor::Env.new(message_sequence, actor_names)
|
22
|
-
end
|
23
|
-
|
24
|
-
shared_examples_for 'master behavior' do
|
25
|
-
it { should eql(actor_env.mailbox(:master).sender) }
|
26
|
-
|
27
|
-
it 'has expected results in sink' do
|
28
|
-
subject
|
29
|
-
expect(sink.results).to eql(expected_results)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'consumes all messages' do
|
33
|
-
subject
|
34
|
-
expect(message_sequence.messages).to eql([])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
let(:config) do
|
39
|
-
Mutant::Parallel::Config.new(
|
40
|
-
env: actor_env,
|
41
|
-
jobs: 1,
|
42
|
-
processor: processor,
|
43
|
-
sink: sink,
|
44
|
-
source: Mutant::Parallel::Source::Array.new([job_payload_a, job_payload_b])
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
class FakeSink
|
49
|
-
def initialize
|
50
|
-
@results = []
|
51
|
-
@stop = false
|
52
|
-
end
|
53
|
-
|
54
|
-
attr_reader :results
|
55
|
-
|
56
|
-
def status
|
57
|
-
@results.length
|
58
|
-
end
|
59
|
-
|
60
|
-
def result(result)
|
61
|
-
@results << result
|
62
|
-
end
|
63
|
-
|
64
|
-
def stop
|
65
|
-
@stop = true
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
def stop?
|
70
|
-
@stop
|
71
|
-
end
|
72
|
-
end # FakeSink
|
73
|
-
|
74
|
-
# Needed because of rubies undefined-ivar-read-is-nil stuff
|
75
|
-
describe 'object initialization' do
|
76
|
-
let(:object) { described_class.__send__(:new, config, actor_env.mailbox(:master)) }
|
77
|
-
|
78
|
-
it 'initializes falsy ivars' do
|
79
|
-
expect(object.instance_variable_get(:@stop)).to be(false)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '.call' do
|
84
|
-
|
85
|
-
before do
|
86
|
-
expect(Mutant::Parallel::Worker).to receive(:run).with(
|
87
|
-
mailbox: actor_env.mailbox(:worker_a),
|
88
|
-
processor: processor,
|
89
|
-
parent: actor_env.mailbox(:master).sender
|
90
|
-
).and_return(worker_a)
|
91
|
-
end
|
92
|
-
|
93
|
-
subject { described_class.call(config) }
|
94
|
-
|
95
|
-
context 'with multiple workers configured' do
|
96
|
-
let(:config) { super().with(jobs: 2) }
|
97
|
-
let(:expected_results) { [] }
|
98
|
-
|
99
|
-
before do
|
100
|
-
expect(Mutant::Parallel::Worker).to receive(:run).with(
|
101
|
-
mailbox: actor_env.mailbox(:worker_b),
|
102
|
-
processor: processor,
|
103
|
-
parent: actor_env.mailbox(:master).sender
|
104
|
-
).and_return(worker_b)
|
105
|
-
|
106
|
-
sink.stop
|
107
|
-
|
108
|
-
message_sequence.add(:master, :ready, worker_a)
|
109
|
-
message_sequence.add(:worker_a, :stop)
|
110
|
-
|
111
|
-
message_sequence.add(:master, :ready, worker_b)
|
112
|
-
message_sequence.add(:worker_b, :stop)
|
113
|
-
|
114
|
-
message_sequence.add(:master, :stop, parent)
|
115
|
-
message_sequence.add(:parent, :stop)
|
116
|
-
end
|
117
|
-
|
118
|
-
include_examples 'master behavior'
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'explicit stop by scheduler state' do
|
122
|
-
context 'before jobs are processed' do
|
123
|
-
let(:expected_results) { [] }
|
124
|
-
|
125
|
-
before do
|
126
|
-
sink.stop
|
127
|
-
|
128
|
-
message_sequence.add(:master, :ready, worker_a)
|
129
|
-
message_sequence.add(:worker_a, :stop)
|
130
|
-
|
131
|
-
message_sequence.add(:master, :stop, parent)
|
132
|
-
message_sequence.add(:parent, :stop)
|
133
|
-
end
|
134
|
-
|
135
|
-
include_examples 'master behavior'
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'while jobs are processed' do
|
139
|
-
let(:sink) do
|
140
|
-
super().instance_eval do
|
141
|
-
def stop?
|
142
|
-
@results.length.equal?(1)
|
143
|
-
end
|
144
|
-
self
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
before do
|
149
|
-
message_sequence.add(:master, :ready, worker_a)
|
150
|
-
message_sequence.add(:worker_a, :job, job_a)
|
151
|
-
message_sequence.add(:master, :result, job_result_a)
|
152
|
-
|
153
|
-
message_sequence.add(:master, :ready, worker_a)
|
154
|
-
message_sequence.add(:worker_a, :stop)
|
155
|
-
|
156
|
-
message_sequence.add(:master, :stop, parent)
|
157
|
-
message_sequence.add(:parent, :stop)
|
158
|
-
end
|
159
|
-
|
160
|
-
it { should eql(actor_env.mailbox(:master).sender) }
|
161
|
-
|
162
|
-
it 'consumes all messages' do
|
163
|
-
expect { subject }.to change(&message_sequence.method(:consumed?)).from(false).to(true)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'external stop' do
|
169
|
-
context 'after jobs are done' do
|
170
|
-
let(:expected_results) { [job_result_payload_a, job_result_payload_b] }
|
171
|
-
|
172
|
-
before do
|
173
|
-
message_sequence.add(:master, :ready, worker_a)
|
174
|
-
message_sequence.add(:worker_a, :job, job_a)
|
175
|
-
message_sequence.add(:master, :result, job_result_a)
|
176
|
-
|
177
|
-
message_sequence.add(:master, :ready, worker_a)
|
178
|
-
message_sequence.add(:worker_a, :job, job_b)
|
179
|
-
message_sequence.add(:master, :result, job_result_b)
|
180
|
-
|
181
|
-
message_sequence.add(:master, :ready, worker_a)
|
182
|
-
message_sequence.add(:worker_a, :stop)
|
183
|
-
|
184
|
-
message_sequence.add(:master, :stop, parent)
|
185
|
-
message_sequence.add(:parent, :stop)
|
186
|
-
end
|
187
|
-
|
188
|
-
include_examples 'master behavior'
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'when no jobs are active' do
|
192
|
-
let(:expected_results) { [job_result_payload_a] }
|
193
|
-
|
194
|
-
before do
|
195
|
-
message_sequence.add(:master, :ready, worker_a)
|
196
|
-
message_sequence.add(:worker_a, :job, job_a)
|
197
|
-
message_sequence.add(:master, :stop, parent)
|
198
|
-
message_sequence.add(:master, :result, job_result_a)
|
199
|
-
|
200
|
-
message_sequence.add(:master, :ready, worker_a)
|
201
|
-
message_sequence.add(:worker_a, :stop)
|
202
|
-
|
203
|
-
message_sequence.add(:parent, :stop)
|
204
|
-
end
|
205
|
-
|
206
|
-
include_examples 'master behavior'
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'before any job got processed' do
|
210
|
-
let(:expected_results) { [] }
|
211
|
-
|
212
|
-
before do
|
213
|
-
message_sequence.add(:master, :stop, parent)
|
214
|
-
message_sequence.add(:master, :ready, worker_a)
|
215
|
-
message_sequence.add(:worker_a, :stop)
|
216
|
-
message_sequence.add(:parent, :stop)
|
217
|
-
end
|
218
|
-
|
219
|
-
include_examples 'master behavior'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'requesting status' do
|
224
|
-
context 'when jobs are done' do
|
225
|
-
let(:expected_status) { Mutant::Parallel::Status.new(payload: 2, active_jobs: Set.new, done: true) }
|
226
|
-
let(:expected_results) { [job_result_payload_a, job_result_payload_b] }
|
227
|
-
|
228
|
-
before do
|
229
|
-
message_sequence.add(:master, :ready, worker_a)
|
230
|
-
message_sequence.add(:worker_a, :job, job_a)
|
231
|
-
message_sequence.add(:master, :result, job_result_a)
|
232
|
-
|
233
|
-
message_sequence.add(:master, :ready, worker_a)
|
234
|
-
message_sequence.add(:worker_a, :job, job_b)
|
235
|
-
message_sequence.add(:master, :result, job_result_b)
|
236
|
-
|
237
|
-
message_sequence.add(:master, :ready, worker_a)
|
238
|
-
message_sequence.add(:worker_a, :stop)
|
239
|
-
|
240
|
-
message_sequence.add(:master, :status, parent)
|
241
|
-
|
242
|
-
# Special bit to kill a mutation that results in mutable active_jobs being passed.
|
243
|
-
message_sequence.add(:parent, :status, expected_status) do |message|
|
244
|
-
expect(message.payload.active_jobs.frozen?).to be(true)
|
245
|
-
end
|
246
|
-
message_sequence.add(:master, :stop, parent)
|
247
|
-
message_sequence.add(:parent, :stop)
|
248
|
-
end
|
249
|
-
|
250
|
-
include_examples 'master behavior'
|
251
|
-
end
|
252
|
-
|
253
|
-
context 'just after scheduler stops' do
|
254
|
-
let(:expected_status) { Mutant::Parallel::Status.new(payload: 1, active_jobs: [].to_set, done: true) }
|
255
|
-
let(:expected_results) { [job_result_payload_a] }
|
256
|
-
|
257
|
-
let(:sink) do
|
258
|
-
super().instance_eval do
|
259
|
-
def stop?
|
260
|
-
@results.length.equal?(1)
|
261
|
-
end
|
262
|
-
self
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
before do
|
267
|
-
message_sequence.add(:master, :ready, worker_a)
|
268
|
-
message_sequence.add(:worker_a, :job, job_a)
|
269
|
-
message_sequence.add(:master, :result, job_result_a)
|
270
|
-
|
271
|
-
message_sequence.add(:master, :status, parent)
|
272
|
-
message_sequence.add(:parent, :status, expected_status)
|
273
|
-
|
274
|
-
message_sequence.add(:master, :ready, worker_a)
|
275
|
-
message_sequence.add(:worker_a, :stop)
|
276
|
-
|
277
|
-
message_sequence.add(:master, :stop, parent)
|
278
|
-
message_sequence.add(:parent, :stop)
|
279
|
-
end
|
280
|
-
|
281
|
-
include_examples 'master behavior'
|
282
|
-
end
|
283
|
-
|
284
|
-
context 'when jobs are active' do
|
285
|
-
let(:expected_status) { Mutant::Parallel::Status.new(payload: 1, active_jobs: [job_b].to_set, done: false) }
|
286
|
-
let(:expected_results) { [job_result_payload_a, job_result_payload_b] }
|
287
|
-
|
288
|
-
before do
|
289
|
-
message_sequence.add(:master, :ready, worker_a)
|
290
|
-
message_sequence.add(:worker_a, :job, job_a)
|
291
|
-
message_sequence.add(:master, :result, job_result_a)
|
292
|
-
|
293
|
-
message_sequence.add(:master, :ready, worker_a)
|
294
|
-
message_sequence.add(:worker_a, :job, job_b)
|
295
|
-
|
296
|
-
message_sequence.add(:master, :status, parent)
|
297
|
-
message_sequence.add(:parent, :status, expected_status)
|
298
|
-
|
299
|
-
message_sequence.add(:master, :result, job_result_b)
|
300
|
-
|
301
|
-
message_sequence.add(:master, :ready, worker_a)
|
302
|
-
message_sequence.add(:worker_a, :stop)
|
303
|
-
|
304
|
-
message_sequence.add(:master, :stop, parent)
|
305
|
-
message_sequence.add(:parent, :stop)
|
306
|
-
end
|
307
|
-
|
308
|
-
include_examples 'master behavior'
|
309
|
-
end
|
310
|
-
|
311
|
-
context 'before jobs are done' do
|
312
|
-
let(:expected_status) { Mutant::Parallel::Status.new(payload: 0, active_jobs: Set.new, done: false) }
|
313
|
-
let(:expected_results) { [] }
|
314
|
-
|
315
|
-
before do
|
316
|
-
message_sequence.add(:master, :status, parent)
|
317
|
-
message_sequence.add(:parent, :status, expected_status)
|
318
|
-
message_sequence.add(:master, :stop, parent)
|
319
|
-
message_sequence.add(:master, :ready, worker_a)
|
320
|
-
message_sequence.add(:worker_a, :stop)
|
321
|
-
message_sequence.add(:parent, :stop)
|
322
|
-
end
|
323
|
-
|
324
|
-
include_examples 'master behavior'
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context 'unhandled message received' do
|
329
|
-
before do
|
330
|
-
message_sequence.add(:master, :foo, parent)
|
331
|
-
end
|
332
|
-
|
333
|
-
it 'raises message' do
|
334
|
-
expect { subject }.to raise_error(Mutant::Actor::ProtocolError, 'Unexpected message: :foo')
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|