knapsack_pro 8.3.3 → 9.0.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/.circleci/config.yml +1 -2
- data/.gitignore +0 -1
- data/CHANGELOG.md +23 -2
- data/README.md +1 -1
- data/knapsack_pro.gemspec +1 -1
- data/lib/knapsack_pro/client/api/v1/queues.rb +1 -0
- data/lib/knapsack_pro/client/connection.rb +97 -52
- data/lib/knapsack_pro/config/ci/github_actions.rb +6 -4
- data/lib/knapsack_pro/queue_allocator.rb +13 -12
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/knapsack_pro.rb +9 -3
- data/spec/integration/runners/fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/cucumber_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/minitest_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/rspec_runner_fallback_spec.rb +4 -4
- data/spec/integration/runners/queue/rspec_runner_spec.rb +20 -20
- data/spec/knapsack_pro/client/api/v1/queues_spec.rb +3 -1
- data/spec/knapsack_pro/client/connection_spec.rb +19 -15
- data/spec/knapsack_pro/config/ci/github_actions_spec.rb +40 -18
- data/spec/knapsack_pro/config/env_spec.rb +330 -352
- data/spec/knapsack_pro/formatters/time_tracker_spec.rb +448 -0
- data/spec/knapsack_pro/pure/queue/rspec_pure_spec.rb +5 -5
- data/spec/knapsack_pro/test_case_detectors/rspec_test_example_detector_spec.rb +1 -1
- data/spec/knapsack_pro_spec.rb +63 -39
- data/spec_time_tracker/spec_helper.rb +29 -0
- metadata +6 -9
- data/bin/test +0 -15
- data/lib/knapsack_pro/logger_wrapper.rb +0 -22
- data/spec/knapsack_pro/formatters/time_tracker_specs.rb +0 -545
- data/spec/knapsack_pro/logger_wrapper_spec.rb +0 -21
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: knapsack_pro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 9.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ArturT
|
|
@@ -215,7 +215,6 @@ files:
|
|
|
215
215
|
- README.md
|
|
216
216
|
- Rakefile
|
|
217
217
|
- bin/knapsack_pro
|
|
218
|
-
- bin/test
|
|
219
218
|
- knapsack_pro.gemspec
|
|
220
219
|
- lib/knapsack_pro.rb
|
|
221
220
|
- lib/knapsack_pro/adapters/base_adapter.rb
|
|
@@ -258,7 +257,6 @@ files:
|
|
|
258
257
|
- lib/knapsack_pro/formatters/time_tracker.rb
|
|
259
258
|
- lib/knapsack_pro/formatters/time_tracker_fetcher.rb
|
|
260
259
|
- lib/knapsack_pro/hooks/queue.rb
|
|
261
|
-
- lib/knapsack_pro/logger_wrapper.rb
|
|
262
260
|
- lib/knapsack_pro/mask_string.rb
|
|
263
261
|
- lib/knapsack_pro/presenter.rb
|
|
264
262
|
- lib/knapsack_pro/pure/queue/rspec_pure.rb
|
|
@@ -359,9 +357,8 @@ files:
|
|
|
359
357
|
- spec/knapsack_pro/crypto/digestor_spec.rb
|
|
360
358
|
- spec/knapsack_pro/crypto/encryptor_spec.rb
|
|
361
359
|
- spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb
|
|
362
|
-
- spec/knapsack_pro/formatters/
|
|
360
|
+
- spec/knapsack_pro/formatters/time_tracker_spec.rb
|
|
363
361
|
- spec/knapsack_pro/hooks/queue_spec.rb
|
|
364
|
-
- spec/knapsack_pro/logger_wrapper_spec.rb
|
|
365
362
|
- spec/knapsack_pro/presenter_spec.rb
|
|
366
363
|
- spec/knapsack_pro/pure/queue/rspec_pure_spec.rb
|
|
367
364
|
- spec/knapsack_pro/queue_spec.rb
|
|
@@ -403,6 +400,7 @@ files:
|
|
|
403
400
|
- spec_fake/models/admin_spec.rb
|
|
404
401
|
- spec_fake/models/user_spec.rb
|
|
405
402
|
- spec_fake/spec_helper.rb
|
|
403
|
+
- spec_time_tracker/spec_helper.rb
|
|
406
404
|
- test_fake/a_test.rb
|
|
407
405
|
- test_fake/b_test.rb
|
|
408
406
|
homepage: https://knapsackpro.com
|
|
@@ -421,14 +419,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
421
419
|
requirements:
|
|
422
420
|
- - ">="
|
|
423
421
|
- !ruby/object:Gem::Version
|
|
424
|
-
version:
|
|
422
|
+
version: 3.0.0
|
|
425
423
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
426
424
|
requirements:
|
|
427
425
|
- - ">="
|
|
428
426
|
- !ruby/object:Gem::Version
|
|
429
427
|
version: '0'
|
|
430
428
|
requirements: []
|
|
431
|
-
rubygems_version: 3.6.
|
|
429
|
+
rubygems_version: 3.6.9
|
|
432
430
|
specification_version: 4
|
|
433
431
|
summary: Knapsack Pro splits tests across parallel CI nodes and ensures each parallel
|
|
434
432
|
job finish work at a similar time.
|
|
@@ -481,9 +479,8 @@ test_files:
|
|
|
481
479
|
- spec/knapsack_pro/crypto/digestor_spec.rb
|
|
482
480
|
- spec/knapsack_pro/crypto/encryptor_spec.rb
|
|
483
481
|
- spec/knapsack_pro/formatters/time_tracker_fetcher_spec.rb
|
|
484
|
-
- spec/knapsack_pro/formatters/
|
|
482
|
+
- spec/knapsack_pro/formatters/time_tracker_spec.rb
|
|
485
483
|
- spec/knapsack_pro/hooks/queue_spec.rb
|
|
486
|
-
- spec/knapsack_pro/logger_wrapper_spec.rb
|
|
487
484
|
- spec/knapsack_pro/presenter_spec.rb
|
|
488
485
|
- spec/knapsack_pro/pure/queue/rspec_pure_spec.rb
|
|
489
486
|
- spec/knapsack_pro/queue_spec.rb
|
data/bin/test
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
bundle exec ruby spec/knapsack_pro/formatters/time_tracker_specs.rb
|
|
4
|
-
FORMATTERS_EXIT_CODE=$?
|
|
5
|
-
|
|
6
|
-
bundle exec rspec spec
|
|
7
|
-
RSPEC_EXIT_CODE=$?
|
|
8
|
-
|
|
9
|
-
if [ "$FORMATTERS_EXIT_CODE" -ne "0" ]; then
|
|
10
|
-
exit $FORMATTERS_EXIT_CODE
|
|
11
|
-
fi
|
|
12
|
-
|
|
13
|
-
if [ "$RSPEC_EXIT_CODE" -ne "0" ]; then
|
|
14
|
-
exit $RSPEC_EXIT_CODE
|
|
15
|
-
fi
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module KnapsackPro
|
|
4
|
-
class LoggerWrapper
|
|
5
|
-
def initialize(logger)
|
|
6
|
-
@logger = logger
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
attr_reader :logger
|
|
12
|
-
|
|
13
|
-
LOG_LEVEL_METHODS = KnapsackPro::Config::Env::LOG_LEVELS.keys.map(&:to_sym)
|
|
14
|
-
|
|
15
|
-
def method_missing(method, *args, &block)
|
|
16
|
-
if LOG_LEVEL_METHODS.include?(method)
|
|
17
|
-
args[0] = "[knapsack_pro] #{args[0]}"
|
|
18
|
-
end
|
|
19
|
-
logger.send(method, *args, &block)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,545 +0,0 @@
|
|
|
1
|
-
# Named _specs.rb on purpose because it hangs if run as part of `bundle exec rspec`.
|
|
2
|
-
# Use `bundle exec ruby spec/knapsack_pro/formatters/time_tracker_specs.rb` instead.
|
|
3
|
-
|
|
4
|
-
require 'rspec/core'
|
|
5
|
-
require 'knapsack_pro'
|
|
6
|
-
require 'stringio'
|
|
7
|
-
require 'tempfile'
|
|
8
|
-
require_relative '../../../lib/knapsack_pro/formatters/time_tracker'
|
|
9
|
-
|
|
10
|
-
class TestTimeTracker
|
|
11
|
-
def test_single_example
|
|
12
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
13
|
-
false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
spec = <<~SPEC
|
|
17
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
18
|
-
it do
|
|
19
|
-
sleep 0.1
|
|
20
|
-
expect(1).to eq 1
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
SPEC
|
|
24
|
-
|
|
25
|
-
run_specs(spec) do |spec_paths, times|
|
|
26
|
-
raise unless times.size == 1
|
|
27
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
28
|
-
raise unless times[0]["time_execution"] > 0.10
|
|
29
|
-
raise unless times[0]["time_execution"] < 0.15
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_two_files
|
|
34
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
35
|
-
false
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
spec_1 = <<~SPEC
|
|
39
|
-
describe "KnapsackPro::Formatters::TimeTracker 1" do
|
|
40
|
-
it do
|
|
41
|
-
sleep 0.1
|
|
42
|
-
expect(1).to eq 1
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
SPEC
|
|
46
|
-
|
|
47
|
-
spec_2 = <<~SPEC
|
|
48
|
-
describe "KnapsackPro::Formatters::TimeTracker 2" do
|
|
49
|
-
it do
|
|
50
|
-
sleep 0.2
|
|
51
|
-
expect(1).to eq 1
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
SPEC
|
|
55
|
-
|
|
56
|
-
run_specs([spec_1, spec_2]) do |spec_paths, times|
|
|
57
|
-
raise unless times.size == 2
|
|
58
|
-
raise unless times.first["path"] == spec_paths.first
|
|
59
|
-
raise unless times.first["time_execution"] > 0.10
|
|
60
|
-
raise unless times.first["time_execution"] < 0.15
|
|
61
|
-
raise unless times.last["path"] == spec_paths.last
|
|
62
|
-
raise unless times.last["time_execution"] > 0.20
|
|
63
|
-
raise unless times.last["time_execution"] < 0.25
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_failing_example
|
|
68
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
69
|
-
false
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
spec = <<~SPEC
|
|
73
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
74
|
-
it do
|
|
75
|
-
sleep 0.1
|
|
76
|
-
expect(1).to eq 2
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
SPEC
|
|
80
|
-
|
|
81
|
-
run_specs(spec) do |spec_paths, times|
|
|
82
|
-
raise unless times.size == 1
|
|
83
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
84
|
-
raise unless times[0]["time_execution"] > 0.10
|
|
85
|
-
raise unless times[0]["time_execution"] < 0.15
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_pending_example
|
|
90
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
91
|
-
false
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
spec = <<~SPEC
|
|
95
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
96
|
-
xit do
|
|
97
|
-
sleep 0.1
|
|
98
|
-
expect(1).to eq 2
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
SPEC
|
|
102
|
-
|
|
103
|
-
run_specs(spec) do |spec_paths, times|
|
|
104
|
-
raise unless times.size == 1
|
|
105
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
106
|
-
raise unless times[0]["time_execution"] == 0.0
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_multiple_top_level_groups
|
|
111
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
112
|
-
false
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
spec = <<~SPEC
|
|
116
|
-
describe "KnapsackPro::Formatters::TimeTracker 1" do
|
|
117
|
-
it do
|
|
118
|
-
sleep 0.1
|
|
119
|
-
expect(1).to eq 1
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "KnapsackPro::Formatters::TimeTracker 2" do
|
|
124
|
-
it do
|
|
125
|
-
sleep 0.2
|
|
126
|
-
expect(1).to eq 1
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
SPEC
|
|
130
|
-
|
|
131
|
-
run_specs(spec) do |spec_paths, times|
|
|
132
|
-
raise unless times.size == 1
|
|
133
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
134
|
-
raise unless times[0]["time_execution"] > 0.30
|
|
135
|
-
raise unless times[0]["time_execution"] < 0.35
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def test_rspec_split_by_test_example
|
|
140
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
141
|
-
true
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
spec = <<~SPEC
|
|
145
|
-
describe "KnapsackPro::Formatters::TimeTracker 1" do
|
|
146
|
-
it do
|
|
147
|
-
expect(1).to eq 1
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it do
|
|
151
|
-
sleep 0.1
|
|
152
|
-
expect(1).to eq 1
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
describe "KnapsackPro::Formatters::TimeTracker 2" do
|
|
157
|
-
it do
|
|
158
|
-
sleep 0.2
|
|
159
|
-
expect(1).to eq 1
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it do
|
|
163
|
-
sleep 0.3
|
|
164
|
-
expect(1).to eq 1
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
SPEC
|
|
168
|
-
|
|
169
|
-
run_specs(spec) do |spec_paths, times|
|
|
170
|
-
raise unless times.size == 4
|
|
171
|
-
spec_path = spec_paths.first
|
|
172
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] < 0.05
|
|
173
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2]" }["time_execution"] > 0.10
|
|
174
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2]" }["time_execution"] < 0.15
|
|
175
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[2:1]" }["time_execution"] > 0.20
|
|
176
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[2:1]" }["time_execution"] < 0.25
|
|
177
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[2:2]" }["time_execution"] > 0.30
|
|
178
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[2:2]" }["time_execution"] < 0.35
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def test_hooks
|
|
183
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
184
|
-
false
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
spec = <<~SPEC
|
|
188
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
189
|
-
before(:all) do
|
|
190
|
-
sleep 0.1
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
before(:each) do
|
|
194
|
-
sleep 0.1
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
after(:each) do
|
|
198
|
-
sleep 0.1
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it do
|
|
202
|
-
expect(1).to eq 1
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
it do
|
|
206
|
-
expect(1).to eq 1
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
after(:all) do
|
|
210
|
-
sleep 0.1
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
SPEC
|
|
214
|
-
|
|
215
|
-
run_specs(spec) do |spec_paths, times|
|
|
216
|
-
raise unless times.size == 1
|
|
217
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
218
|
-
raise unless times[0]["time_execution"] > 0.60
|
|
219
|
-
raise unless times[0]["time_execution"] < 0.65
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def test_nested_hooks
|
|
224
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
225
|
-
false
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
spec = <<~SPEC
|
|
229
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
230
|
-
before(:all) do
|
|
231
|
-
sleep 0.1
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
after(:all) do
|
|
235
|
-
sleep 0.1
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
it do
|
|
239
|
-
expect(1).to eq 1
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
describe do
|
|
243
|
-
before(:all) do
|
|
244
|
-
sleep 0.1
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
after(:all) do
|
|
248
|
-
sleep 0.1
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
it do
|
|
252
|
-
expect(1).to eq 1
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
describe do
|
|
257
|
-
before(:all) do
|
|
258
|
-
sleep 0.1
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
after(:all) do
|
|
262
|
-
sleep 0.1
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
it do
|
|
266
|
-
expect(1).to eq 1
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
SPEC
|
|
271
|
-
|
|
272
|
-
run_specs(spec) do |spec_paths, times|
|
|
273
|
-
raise unless times.size == 1
|
|
274
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
275
|
-
raise unless times[0]["time_execution"] > 0.60
|
|
276
|
-
raise unless times[0]["time_execution"] < 0.65
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def test_hooks_with_rspec_split_by_test_example
|
|
281
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
282
|
-
true
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
spec = <<~SPEC
|
|
286
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
287
|
-
before(:all) do
|
|
288
|
-
sleep 0.1
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
before(:each) do
|
|
292
|
-
sleep 0.1
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
after(:each) do
|
|
296
|
-
sleep 0.1
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
it do
|
|
300
|
-
expect(1).to eq 1
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
it do
|
|
304
|
-
expect(1).to eq 1
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
after(:all) do
|
|
308
|
-
sleep 0.1
|
|
309
|
-
end
|
|
310
|
-
end
|
|
311
|
-
SPEC
|
|
312
|
-
|
|
313
|
-
run_specs(spec) do |spec_paths, times|
|
|
314
|
-
raise unless times.size == 2
|
|
315
|
-
spec_path = spec_paths.first
|
|
316
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] > 0.40
|
|
317
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] < 0.45
|
|
318
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2]" }["time_execution"] > 0.40
|
|
319
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2]" }["time_execution"] < 0.45
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def test_nested_hooks_with_rspec_split_by_test_example
|
|
324
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
325
|
-
true
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
spec = <<~SPEC
|
|
329
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
330
|
-
before(:all) do
|
|
331
|
-
sleep 0.1
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
after(:all) do
|
|
335
|
-
sleep 0.1
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
it do
|
|
339
|
-
expect(1).to eq 1
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
describe do
|
|
343
|
-
before(:all) do
|
|
344
|
-
sleep 0.1
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
after(:all) do
|
|
348
|
-
sleep 0.1
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
it do
|
|
352
|
-
expect(1).to eq 1
|
|
353
|
-
end
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
describe do
|
|
357
|
-
before(:all) do
|
|
358
|
-
sleep 0.1
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
after(:all) do
|
|
362
|
-
sleep 0.1
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
it do
|
|
366
|
-
expect(1).to eq 1
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
end
|
|
370
|
-
SPEC
|
|
371
|
-
|
|
372
|
-
run_specs(spec) do |spec_paths, times|
|
|
373
|
-
raise unless times.size == 3
|
|
374
|
-
spec_path = spec_paths.first
|
|
375
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] > 0.20
|
|
376
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:1]" }["time_execution"] < 0.25
|
|
377
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2:1]" }["time_execution"] > 0.40
|
|
378
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:2:1]" }["time_execution"] < 0.45
|
|
379
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:3:1]" }["time_execution"] > 0.40
|
|
380
|
-
raise unless times.find { |time| time["path"] == "#{spec_path}[1:3:1]" }["time_execution"] < 0.45
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
def test_unknown_path
|
|
386
|
-
KnapsackPro::Formatters::TimeTracker.class_eval do
|
|
387
|
-
alias_method :original_file_path_for, :file_path_for
|
|
388
|
-
|
|
389
|
-
define_method(:file_path_for) do |_example|
|
|
390
|
-
""
|
|
391
|
-
end
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
spec = <<~SPEC
|
|
395
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
396
|
-
it do
|
|
397
|
-
expect(1).to eq 1
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
SPEC
|
|
401
|
-
|
|
402
|
-
run_specs(spec) do |spec_paths, times|
|
|
403
|
-
raise unless times.size == 1
|
|
404
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
405
|
-
raise unless times[0]["time_execution"] == 0.0
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
ensure
|
|
409
|
-
KnapsackPro::Formatters::TimeTracker.class_eval do
|
|
410
|
-
undef :file_path_for
|
|
411
|
-
alias_method :file_path_for, :original_file_path_for
|
|
412
|
-
end
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
def test_empty_group
|
|
416
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
417
|
-
false
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
spec = <<~SPEC
|
|
421
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
422
|
-
end
|
|
423
|
-
SPEC
|
|
424
|
-
|
|
425
|
-
run_specs(spec) do |spec_paths, times|
|
|
426
|
-
raise unless times.size == 1
|
|
427
|
-
raise unless times[0]["path"] == spec_paths.first
|
|
428
|
-
raise unless times[0]["time_execution"] == 0.0
|
|
429
|
-
end
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
def test_duration
|
|
433
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
434
|
-
false
|
|
435
|
-
end
|
|
436
|
-
|
|
437
|
-
spec = <<~SPEC
|
|
438
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
439
|
-
it do
|
|
440
|
-
expect(1).to eq 1
|
|
441
|
-
end
|
|
442
|
-
end
|
|
443
|
-
SPEC
|
|
444
|
-
|
|
445
|
-
run_specs(spec) do |_, _, time_tracker|
|
|
446
|
-
raise unless time_tracker.duration > 0.0
|
|
447
|
-
end
|
|
448
|
-
end
|
|
449
|
-
|
|
450
|
-
def test_unexecuted_test_files
|
|
451
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
452
|
-
false
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
spec = <<~SPEC
|
|
456
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
457
|
-
xit do
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
SPEC
|
|
461
|
-
|
|
462
|
-
run_specs(spec) do |spec_paths, _, time_tracker|
|
|
463
|
-
unexecuted_test_files = ["foo_spec.rb", "bar_spec.rb"]
|
|
464
|
-
# Need to filter because RSpec keeps accumulating state.
|
|
465
|
-
time_tracker.scheduled_paths = spec_paths + unexecuted_test_files
|
|
466
|
-
files = time_tracker
|
|
467
|
-
.unexecuted_test_files
|
|
468
|
-
.filter { |file| spec_paths.include?(file) || unexecuted_test_files.include?(file) }
|
|
469
|
-
|
|
470
|
-
raise unless files.size == 3
|
|
471
|
-
end
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
def test_subset
|
|
475
|
-
KnapsackPro::Formatters::TimeTracker.define_method(:rspec_split_by_test_example?) do |_file|
|
|
476
|
-
false
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
spec = <<~SPEC
|
|
480
|
-
describe "KnapsackPro::Formatters::TimeTracker" do
|
|
481
|
-
it "works" do
|
|
482
|
-
sleep 0.1
|
|
483
|
-
expect(1).to eq 1
|
|
484
|
-
end
|
|
485
|
-
end
|
|
486
|
-
SPEC
|
|
487
|
-
|
|
488
|
-
run_specs(spec) do |spec_paths, times, time_tracker|
|
|
489
|
-
# Need to filter because RSpec keeps accumulating state.
|
|
490
|
-
files = time_tracker
|
|
491
|
-
.batch
|
|
492
|
-
.filter { |file| spec_paths.include?(file["path"]) }
|
|
493
|
-
|
|
494
|
-
raise unless files.size == 1
|
|
495
|
-
raise unless files[0]["path"] == spec_paths.first
|
|
496
|
-
raise unless files[0]["time_execution"] > 0.10
|
|
497
|
-
raise unless files[0]["time_execution"] < 0.15
|
|
498
|
-
end
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
private
|
|
502
|
-
|
|
503
|
-
def run_specs(specs)
|
|
504
|
-
files = Array(specs).map.with_index do |spec, i|
|
|
505
|
-
file = Tempfile.new(["tmp_time_tracker_#{i}", "_spec.rb"], "./spec/knapsack_pro/formatters/")
|
|
506
|
-
file.write(spec)
|
|
507
|
-
file.rewind
|
|
508
|
-
file
|
|
509
|
-
end
|
|
510
|
-
|
|
511
|
-
paths = files.map(&:path).map { _1.sub("./", "") }
|
|
512
|
-
|
|
513
|
-
options = ::RSpec::Core::ConfigurationOptions.new([
|
|
514
|
-
"--format", KnapsackPro::Formatters::TimeTracker.to_s,
|
|
515
|
-
*paths,
|
|
516
|
-
])
|
|
517
|
-
runner = ::RSpec::Core::Runner.new(options)
|
|
518
|
-
runner.run(StringIO.new, StringIO.new)
|
|
519
|
-
|
|
520
|
-
time_tracker = runner.configuration.formatters.find { |f| f.class.to_s == KnapsackPro::Formatters::TimeTracker.to_s }
|
|
521
|
-
# Need to filter because RSpec keeps accumulating state.
|
|
522
|
-
time_tracker.scheduled_paths = paths
|
|
523
|
-
times = time_tracker
|
|
524
|
-
.queue
|
|
525
|
-
.sort_by { |time| time["path"] }
|
|
526
|
-
.filter do |time|
|
|
527
|
-
paths.any? { |path| time["path"].start_with?(path) }
|
|
528
|
-
end
|
|
529
|
-
yield(paths, times, time_tracker)
|
|
530
|
-
|
|
531
|
-
ensure
|
|
532
|
-
# Need to reset because RSpec keeps reusing the same instance.
|
|
533
|
-
time_tracker.instance_variable_set(:@queue, {}) if time_tracker
|
|
534
|
-
time_tracker.instance_variable_set(:@started, time_tracker.send(:now)) if time_tracker
|
|
535
|
-
end
|
|
536
|
-
end
|
|
537
|
-
|
|
538
|
-
TestTimeTracker
|
|
539
|
-
.instance_methods
|
|
540
|
-
.filter { |method| method.to_s.start_with?("test_") }
|
|
541
|
-
.shuffle
|
|
542
|
-
.each do |method|
|
|
543
|
-
puts method
|
|
544
|
-
TestTimeTracker.new.public_send(method)
|
|
545
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
describe KnapsackPro::LoggerWrapper do
|
|
2
|
-
let(:io) { StringIO.new }
|
|
3
|
-
let(:logger) { ::Logger.new(io) }
|
|
4
|
-
let(:logger_wrapper) { described_class.new(logger) }
|
|
5
|
-
|
|
6
|
-
subject { io.string }
|
|
7
|
-
|
|
8
|
-
[:debug, :info, :warn, :error, :fatal].each do |log_level|
|
|
9
|
-
describe "##{log_level}" do
|
|
10
|
-
before { logger_wrapper.public_send(log_level, 'Test message') }
|
|
11
|
-
|
|
12
|
-
it { should include "[knapsack_pro] Test message\n" }
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it 'can set logger level via logger wrapper' do
|
|
17
|
-
logger_wrapper.level = ::Logger::INFO
|
|
18
|
-
|
|
19
|
-
expect(logger_wrapper.level).to eq 1
|
|
20
|
-
end
|
|
21
|
-
end
|