knapsack_pro 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +12 -7
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +35 -8
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +52 -0
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +48 -7
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1d109eab55a41f0ad16de94f9675299a8df07eca2c1bca2edf92c588fe2adb
|
4
|
+
data.tar.gz: 05d6fec7a5c6a8d594b78e80eecff4bad0282e4f10bb5e772eae25d659c39bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01bd206ae95503b54abad29acc5bd29e658b5ee9b8fe0c7d31b1a78e8aee0b364a0d74f619306633e599f004a2e2fdb8c8b188b389e5e26255838c9b17b45c33
|
7
|
+
data.tar.gz: 7067285b1dc323859d8547df7c6d3edcb7c1cfa2f14251be9a857d957212d08666fdd82ae1426c7a614d93692b86131283606e6b57e73f9a1064b47b4af9355a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 3.4.1
|
4
|
+
|
5
|
+
* Improve the RSpec Queue Mode runner log output (add seed)
|
6
|
+
|
7
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/178
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v3.4.0...v3.4.1
|
10
|
+
|
3
11
|
### 3.4.0
|
4
12
|
|
5
13
|
* Update documentation and code because the encryption feature does not work with the RSpec split by examples feature
|
@@ -12,16 +12,15 @@ module KnapsackPro
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.has_tag_option?(cli_args)
|
15
|
-
|
16
|
-
# -t mytag
|
17
|
-
# -tmytag
|
18
|
-
# --tag mytag
|
19
|
-
# --tag=mytag
|
20
|
-
cli_args.any? { |arg| arg.start_with?('-t') || arg.start_with?('--tag') }
|
15
|
+
!!parsed_options(cli_args)&.[](:inclusion_filter)
|
21
16
|
end
|
22
17
|
|
23
18
|
def self.has_format_option?(cli_args)
|
24
|
-
cli_args
|
19
|
+
!!parsed_options(cli_args)&.[](:formatters)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.order_option(cli_args)
|
23
|
+
parsed_options(cli_args)&.[](:order)
|
25
24
|
end
|
26
25
|
|
27
26
|
def self.test_path(example)
|
@@ -107,6 +106,12 @@ module KnapsackPro
|
|
107
106
|
def self.rspec_configuration
|
108
107
|
::RSpec.configuration
|
109
108
|
end
|
109
|
+
|
110
|
+
def self.parsed_options(cli_args)
|
111
|
+
::RSpec::Core::Parser.parse(cli_args)
|
112
|
+
rescue SystemExit
|
113
|
+
nil
|
114
|
+
end
|
110
115
|
end
|
111
116
|
|
112
117
|
# This is added to provide backwards compatibility
|
@@ -2,6 +2,8 @@ module KnapsackPro
|
|
2
2
|
module Runners
|
3
3
|
module Queue
|
4
4
|
class RSpecRunner < BaseRunner
|
5
|
+
@@used_seed = nil
|
6
|
+
|
5
7
|
def self.run(args)
|
6
8
|
require 'rspec/core'
|
7
9
|
require_relative '../../formatters/rspec_queue_summary_formatter'
|
@@ -11,7 +13,6 @@ module KnapsackPro
|
|
11
13
|
ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] = 'true'
|
12
14
|
ENV['KNAPSACK_PRO_QUEUE_ID'] = KnapsackPro::Config::EnvGenerator.set_queue_id
|
13
15
|
|
14
|
-
adapter_class = KnapsackPro::Adapters::RSpecAdapter
|
15
16
|
KnapsackPro::Config::Env.set_test_runner_adapter(adapter_class)
|
16
17
|
runner = new(adapter_class)
|
17
18
|
|
@@ -61,6 +62,8 @@ module KnapsackPro
|
|
61
62
|
KnapsackPro::Formatters::RSpecQueueSummaryFormatter.print_summary
|
62
63
|
KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension.print_summary
|
63
64
|
|
65
|
+
args += ['--seed', @@used_seed] if @@used_seed
|
66
|
+
|
64
67
|
log_rspec_command(args, all_test_file_paths, :end_of_queue)
|
65
68
|
end
|
66
69
|
|
@@ -82,12 +85,15 @@ module KnapsackPro
|
|
82
85
|
all_test_file_paths += test_file_paths
|
83
86
|
cli_args = args + test_file_paths
|
84
87
|
|
85
|
-
log_rspec_command(args, test_file_paths, :subset_queue)
|
86
|
-
|
87
88
|
options = ::RSpec::Core::ConfigurationOptions.new(cli_args)
|
88
|
-
|
89
|
+
rspec_runner = ::RSpec::Core::Runner.new(options)
|
90
|
+
|
91
|
+
exit_code = rspec_runner.run($stderr, $stdout)
|
89
92
|
exitstatus = exit_code if exit_code != 0
|
90
93
|
|
94
|
+
printable_args = args_with_seed_option_added_when_viable(args, rspec_runner)
|
95
|
+
log_rspec_command(printable_args, test_file_paths, :subset_queue)
|
96
|
+
|
91
97
|
rspec_clear_examples
|
92
98
|
|
93
99
|
KnapsackPro::Hooks::Queue.call_after_subset_queue
|
@@ -107,19 +113,22 @@ module KnapsackPro
|
|
107
113
|
|
108
114
|
private
|
109
115
|
|
116
|
+
def self.adapter_class
|
117
|
+
KnapsackPro::Adapters::RSpecAdapter
|
118
|
+
end
|
119
|
+
|
110
120
|
def self.log_rspec_command(cli_args, test_file_paths, type)
|
111
121
|
case type
|
112
122
|
when :subset_queue
|
113
|
-
KnapsackPro.logger.info("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine
|
123
|
+
KnapsackPro.logger.info("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
|
114
124
|
when :end_of_queue
|
115
125
|
KnapsackPro.logger.info("To retry all the tests assigned to this CI node, please run the following command on your machine:")
|
116
126
|
end
|
117
127
|
|
118
|
-
|
119
|
-
stringify_cli_args.slice!("--format #{KnapsackPro::Formatters::RSpecQueueSummaryFormatter}")
|
128
|
+
stringified_cli_args = cli_args.join(' ').sub(" --format #{KnapsackPro::Formatters::RSpecQueueSummaryFormatter}", '')
|
120
129
|
|
121
130
|
KnapsackPro.logger.info(
|
122
|
-
"bundle exec rspec #{
|
131
|
+
"bundle exec rspec #{stringified_cli_args} " +
|
123
132
|
KnapsackPro::TestFilePresenter.stringify_paths(test_file_paths)
|
124
133
|
)
|
125
134
|
end
|
@@ -151,6 +160,24 @@ module KnapsackPro
|
|
151
160
|
::RSpec.configuration.reset_filters
|
152
161
|
end
|
153
162
|
end
|
163
|
+
|
164
|
+
def self.args_with_seed_option_added_when_viable(args, rspec_runner)
|
165
|
+
order_option = adapter_class.order_option(args)
|
166
|
+
|
167
|
+
if order_option
|
168
|
+
# Don't add the seed option for order other than random, e.g. `defined`
|
169
|
+
return args unless order_option.include?('rand')
|
170
|
+
# Don't add the seed option if the seed is already set in args, e.g. `rand:12345`
|
171
|
+
return args if order_option.to_s.split(':')[1]
|
172
|
+
end
|
173
|
+
|
174
|
+
# Don't add the seed option if the seed was not used (i.e. a different order is being used, e.g. `defined`)
|
175
|
+
return args unless rspec_runner.configuration.seed_used?
|
176
|
+
|
177
|
+
@@used_seed = rspec_runner.configuration.seed.to_s
|
178
|
+
|
179
|
+
args + ['--seed', @@used_seed]
|
180
|
+
end
|
154
181
|
end
|
155
182
|
end
|
156
183
|
end
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -110,6 +110,58 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
describe '.order_option' do
|
114
|
+
subject { described_class.order_option(cli_args) }
|
115
|
+
|
116
|
+
context "when order is 'defined'" do
|
117
|
+
let(:cli_args) { ['--order', 'defined'] }
|
118
|
+
|
119
|
+
it { expect(subject).to eq 'defined' }
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when order is 'recently-modified'" do
|
123
|
+
let(:cli_args) { ['--order', 'recently-modified'] }
|
124
|
+
|
125
|
+
it { expect(subject).to eq 'recently-modified' }
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when order is 'rand'" do
|
129
|
+
let(:cli_args) { ['--order', 'rand'] }
|
130
|
+
|
131
|
+
it { expect(subject).to eq 'rand' }
|
132
|
+
|
133
|
+
context 'with the seed' do
|
134
|
+
let(:cli_args) { ['--order', 'rand:123456'] }
|
135
|
+
|
136
|
+
it { expect(subject).to eq 'rand:123456' }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when order is 'random'" do
|
141
|
+
let(:cli_args) { ['--order', 'random'] }
|
142
|
+
|
143
|
+
it { expect(subject).to eq 'random' }
|
144
|
+
|
145
|
+
context 'with the seed' do
|
146
|
+
let(:cli_args) { ['--order', 'random:123456'] }
|
147
|
+
|
148
|
+
it { expect(subject).to eq 'random:123456' }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when some custom order is specified' do
|
153
|
+
let(:cli_args) { ['--order', 'some-custom-order'] }
|
154
|
+
|
155
|
+
it { expect(subject).to eq 'some-custom-order' }
|
156
|
+
end
|
157
|
+
|
158
|
+
context "when the seed is given with the --seed command" do
|
159
|
+
let(:cli_args) { ['--seed', '123456'] }
|
160
|
+
|
161
|
+
it { expect(subject).to eq 'rand:123456' }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
113
165
|
describe '.test_path' do
|
114
166
|
let(:example_group) do
|
115
167
|
{
|
@@ -177,7 +177,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
177
177
|
describe '.run_tests' do
|
178
178
|
let(:runner) { instance_double(described_class) }
|
179
179
|
let(:can_initialize_queue) { double(:can_initialize_queue) }
|
180
|
-
let(:args) { ['--
|
180
|
+
let(:args) { ['--no-color', '--default-path', 'fake-test-dir'] }
|
181
181
|
let(:exitstatus) { double }
|
182
182
|
let(:all_test_file_paths) { [] }
|
183
183
|
let(:accumulator) do
|
@@ -198,6 +198,8 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
198
198
|
|
199
199
|
context 'when test files exist' do
|
200
200
|
let(:test_file_paths) { ['a_spec.rb', 'b_spec.rb'] }
|
201
|
+
let(:logger) { double }
|
202
|
+
let(:rspec_seed) { 7771 }
|
201
203
|
|
202
204
|
before do
|
203
205
|
subset_queue_id = 'fake-subset-queue-id'
|
@@ -212,7 +214,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
212
214
|
|
213
215
|
options = double
|
214
216
|
expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
|
215
|
-
'--
|
217
|
+
'--no-color',
|
216
218
|
'--default-path', 'fake-test-dir',
|
217
219
|
'a_spec.rb', 'b_spec.rb',
|
218
220
|
]).and_return(options)
|
@@ -226,6 +228,16 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
226
228
|
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_subset_queue)
|
227
229
|
|
228
230
|
expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file)
|
231
|
+
|
232
|
+
configuration = double
|
233
|
+
expect(rspec_core_runner).to receive(:configuration).twice.and_return(configuration)
|
234
|
+
expect(configuration).to receive(:seed_used?).and_return(true)
|
235
|
+
expect(configuration).to receive(:seed).and_return(rspec_seed)
|
236
|
+
|
237
|
+
expect(KnapsackPro).to receive(:logger).twice.and_return(logger)
|
238
|
+
expect(logger).to receive(:info)
|
239
|
+
.with("To retry the last batch of tests fetched from the API Queue, please run the following command on your machine:")
|
240
|
+
expect(logger).to receive(:info).with(/#{args.join(' ')} --seed #{rspec_seed}/)
|
229
241
|
end
|
230
242
|
|
231
243
|
context 'when exit code is zero' do
|
@@ -264,8 +276,13 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
264
276
|
|
265
277
|
context 'when all_test_file_paths exist' do
|
266
278
|
let(:all_test_file_paths) { ['a_spec.rb'] }
|
279
|
+
let(:logger) { double }
|
280
|
+
|
281
|
+
before do
|
282
|
+
described_class.class_variable_set(:@@used_seed, used_seed)
|
283
|
+
|
284
|
+
expect(KnapsackPro).to receive(:logger).twice.and_return(logger)
|
267
285
|
|
268
|
-
it do
|
269
286
|
expect(KnapsackPro::Adapters::RSpecAdapter).to receive(:verify_bind_method_called)
|
270
287
|
|
271
288
|
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
@@ -274,10 +291,33 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
274
291
|
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
275
292
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
276
293
|
|
277
|
-
expect(
|
278
|
-
|
279
|
-
|
280
|
-
|
294
|
+
expect(logger).to receive(:info)
|
295
|
+
.with('To retry all the tests assigned to this CI node, please run the following command on your machine:')
|
296
|
+
expect(logger).to receive(:info).with(logged_rspec_command_matcher)
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'when @@used_seed has been set' do
|
300
|
+
let(:used_seed) { '8333' }
|
301
|
+
let(:logged_rspec_command_matcher) { /#{args.join(' ')} --seed #{used_seed} \"a_spec.rb"/ }
|
302
|
+
|
303
|
+
it do
|
304
|
+
expect(subject).to eq({
|
305
|
+
status: :completed,
|
306
|
+
exitstatus: exitstatus,
|
307
|
+
})
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'when @@used_seed has not been set' do
|
312
|
+
let(:used_seed) { nil }
|
313
|
+
let(:logged_rspec_command_matcher) { /#{args.join(' ')} \"a_spec.rb"/ }
|
314
|
+
|
315
|
+
it do
|
316
|
+
expect(subject).to eq({
|
317
|
+
status: :completed,
|
318
|
+
exitstatus: exitstatus,
|
319
|
+
})
|
320
|
+
end
|
281
321
|
end
|
282
322
|
end
|
283
323
|
|
@@ -287,6 +327,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
287
327
|
it do
|
288
328
|
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
289
329
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
330
|
+
expect(KnapsackPro).to_not receive(:logger)
|
290
331
|
|
291
332
|
expect(subject).to eq({
|
292
333
|
status: :completed,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -390,7 +390,7 @@ metadata:
|
|
390
390
|
documentation_uri: https://docs.knapsackpro.com/integration/
|
391
391
|
homepage_uri: https://knapsackpro.com
|
392
392
|
source_code_uri: https://github.com/KnapsackPro/knapsack_pro-ruby
|
393
|
-
post_install_message:
|
393
|
+
post_install_message:
|
394
394
|
rdoc_options: []
|
395
395
|
require_paths:
|
396
396
|
- lib
|
@@ -405,8 +405,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
405
405
|
- !ruby/object:Gem::Version
|
406
406
|
version: '0'
|
407
407
|
requirements: []
|
408
|
-
rubygems_version: 3.
|
409
|
-
signing_key:
|
408
|
+
rubygems_version: 3.1.6
|
409
|
+
signing_key:
|
410
410
|
specification_version: 4
|
411
411
|
summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
|
412
412
|
job finish work at a similar time.
|