knapsack 0.5.0 → 1.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/.travis.yml +16 -16
- data/CHANGELOG.md +6 -0
- data/README.md +162 -61
- data/TODO.md +1 -1
- data/bin/print_header.sh +5 -0
- data/knapsack.gemspec +4 -2
- data/{knapsack_report.json → knapsack_rspec_report.json} +0 -0
- data/lib/knapsack.rb +5 -2
- data/lib/knapsack/adapters/base_adapter.rb +17 -1
- data/lib/knapsack/adapters/cucumber_adapter.rb +40 -0
- data/lib/knapsack/adapters/rspec_adapter.rb +5 -2
- data/lib/knapsack/allocator.rb +10 -11
- data/lib/knapsack/allocator_builder.rb +33 -0
- data/lib/knapsack/config/env.rb +30 -0
- data/lib/knapsack/config/tracker.rb +19 -0
- data/lib/knapsack/distributors/base_distributor.rb +18 -28
- data/lib/knapsack/distributors/leftover_distributor.rb +14 -14
- data/lib/knapsack/distributors/report_distributor.rb +33 -33
- data/lib/knapsack/presenter.rb +4 -4
- data/lib/knapsack/report.rb +13 -11
- data/lib/knapsack/tracker.rb +20 -15
- data/lib/knapsack/version.rb +1 -1
- data/lib/tasks/knapsack_cucumber.rake +19 -0
- data/lib/tasks/knapsack_rspec.rake +19 -0
- data/spec/knapsack/adapters/cucumber_adapter_spec.rb +69 -0
- data/spec/knapsack/adapters/rspec_adapter_spec.rb +26 -18
- data/spec/knapsack/allocator_builder_spec.rb +88 -0
- data/spec/knapsack/allocator_spec.rb +26 -27
- data/spec/knapsack/{config_spec.rb → config/env_spec.rb} +9 -32
- data/spec/knapsack/config/tracker_spec.rb +24 -0
- data/spec/knapsack/distributors/base_distributor_spec.rb +26 -39
- data/spec/knapsack/distributors/leftover_distributor_spec.rb +49 -31
- data/spec/knapsack/distributors/report_distributor_spec.rb +35 -41
- data/spec/knapsack/presenter_spec.rb +5 -5
- data/spec/knapsack/report_spec.rb +5 -9
- data/spec/knapsack/task_loader_spec.rb +4 -2
- data/spec/knapsack/tracker_spec.rb +14 -14
- data/spec/support/mocks/cucumber.rb +12 -0
- data/spec/support/shared_examples/adapter.rb +0 -4
- data/spec_examples/leftover/1_spec.rb +1 -1
- data/spec_examples/leftover/a_spec.rb +1 -1
- data/spec_examples/spec_helper.rb +1 -1
- metadata +54 -11
- data/lib/knapsack/config.rb +0 -40
- data/lib/tasks/knapsack.rake +0 -20
@@ -1,6 +1,6 @@
|
|
1
1
|
describe Knapsack::Presenter do
|
2
2
|
let(:tracker) { instance_double(Knapsack::Tracker) }
|
3
|
-
let(:
|
3
|
+
let(:test_files_with_time) do
|
4
4
|
{
|
5
5
|
'a_spec.rb' => 1.0,
|
6
6
|
'b_spec.rb' => 0.4
|
@@ -10,17 +10,17 @@ describe Knapsack::Presenter do
|
|
10
10
|
describe 'report methods' do
|
11
11
|
before do
|
12
12
|
expect(Knapsack).to receive(:tracker) { tracker }
|
13
|
-
expect(tracker).to receive(:
|
13
|
+
expect(tracker).to receive(:test_files_with_time).and_return(test_files_with_time)
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '.report_yml' do
|
17
17
|
subject { described_class.report_yml }
|
18
|
-
it { should eql
|
18
|
+
it { should eql test_files_with_time.to_yaml }
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '.report_json' do
|
22
22
|
subject { described_class.report_json }
|
23
|
-
it { should eql JSON.pretty_generate(
|
23
|
+
it { should eql JSON.pretty_generate(test_files_with_time) }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -32,7 +32,7 @@ describe Knapsack::Presenter do
|
|
32
32
|
expect(tracker).to receive(:global_time).and_return(60*62+3)
|
33
33
|
end
|
34
34
|
|
35
|
-
it { should eql "\nKnapsack global time execution for
|
35
|
+
it { should eql "\nKnapsack global time execution for tests: 01h 02m 03s" }
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '.report_details' do
|
@@ -7,27 +7,23 @@ describe Knapsack::Report do
|
|
7
7
|
|
8
8
|
describe '#config' do
|
9
9
|
context 'when passed options' do
|
10
|
-
let(:
|
10
|
+
let(:args) do
|
11
11
|
{
|
12
|
-
report_path: '
|
12
|
+
report_path: 'knapsack_new_report.json',
|
13
13
|
fake: true
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
it do
|
18
|
-
expect(report.config(
|
19
|
-
report_path: '
|
18
|
+
expect(report.config(args)).to eql({
|
19
|
+
report_path: 'knapsack_new_report.json',
|
20
20
|
fake: true
|
21
21
|
})
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when didn't pass options" do
|
26
|
-
it
|
27
|
-
expect(report.config).to eql({
|
28
|
-
report_path: 'knapsack_report.json'
|
29
|
-
})
|
30
|
-
end
|
26
|
+
it { expect(report.config).to eql({}) }
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
describe Knapsack::TaskLoader do
|
2
2
|
describe '#load_tasks' do
|
3
|
-
let(:
|
3
|
+
let(:rspec_rake_task_path) { "#{Knapsack.root}/lib/tasks/knapsack_rspec.rake" }
|
4
|
+
let(:cucumber_rake_task_path) { "#{Knapsack.root}/lib/tasks/knapsack_cucumber.rake" }
|
4
5
|
|
5
6
|
it do
|
6
|
-
expect(subject).to receive(:import).with(
|
7
|
+
expect(subject).to receive(:import).with(rspec_rake_task_path)
|
8
|
+
expect(subject).to receive(:import).with(cucumber_rake_task_path)
|
7
9
|
subject.load_tasks
|
8
10
|
end
|
9
11
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
shared_examples 'default trakcer attributes' do
|
2
2
|
it { expect(tracker.global_time).to eql 0 }
|
3
|
-
it { expect(tracker.
|
3
|
+
it { expect(tracker.test_files_with_time).to eql({}) }
|
4
4
|
end
|
5
5
|
|
6
6
|
describe Knapsack::Tracker do
|
@@ -45,23 +45,23 @@ describe Knapsack::Tracker do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe '#
|
49
|
-
subject { tracker.
|
48
|
+
describe '#test_path' do
|
49
|
+
subject { tracker.test_path }
|
50
50
|
|
51
|
-
context 'when
|
51
|
+
context 'when test_path not set' do
|
52
52
|
it do
|
53
|
-
expect { subject }.to raise_error("
|
53
|
+
expect { subject }.to raise_error("test_path needs to be set by Knapsack Adapter's bind method")
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context 'when
|
58
|
-
context 'when
|
59
|
-
before { tracker.
|
57
|
+
context 'when test_path set' do
|
58
|
+
context 'when test_path has prefix ./' do
|
59
|
+
before { tracker.test_path = './spec/models/user_spec.rb' }
|
60
60
|
it { should eql 'spec/models/user_spec.rb' }
|
61
61
|
end
|
62
62
|
|
63
|
-
context 'when
|
64
|
-
before { tracker.
|
63
|
+
context 'when test_path has not prefix ./' do
|
64
|
+
before { tracker.test_path = 'spec/models/user_spec.rb' }
|
65
65
|
it { should eql 'spec/models/user_spec.rb' }
|
66
66
|
end
|
67
67
|
end
|
@@ -119,12 +119,12 @@ describe Knapsack::Tracker do
|
|
119
119
|
|
120
120
|
describe 'track time execution' do
|
121
121
|
let(:now) { Time.now }
|
122
|
-
let(:
|
122
|
+
let(:test_paths) { ['a_spec.rb', 'b_spec.rb'] }
|
123
123
|
|
124
124
|
before do
|
125
|
-
|
125
|
+
test_paths.each_with_index do |test_path, index|
|
126
126
|
Timecop.freeze(now) do
|
127
|
-
tracker.
|
127
|
+
tracker.test_path = test_path
|
128
128
|
tracker.start_timer
|
129
129
|
end
|
130
130
|
|
@@ -137,7 +137,7 @@ describe Knapsack::Tracker do
|
|
137
137
|
|
138
138
|
it { expect(tracker.global_time).to eql 3.0 }
|
139
139
|
it do
|
140
|
-
expect(tracker.
|
140
|
+
expect(tracker.test_files_with_time).to eql({
|
141
141
|
'a_spec.rb' => 1.0,
|
142
142
|
'b_spec.rb' => 2.0,
|
143
143
|
})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 2.0.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: cucumber
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.3'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: timecop
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,12 +100,27 @@ dependencies:
|
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
102
|
version: '0'
|
89
|
-
|
90
|
-
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: pry
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
description: Parallel tests across CI server nodes based on each test file's time
|
118
|
+
execution. It generates a test time execution report and uses it for future test
|
91
119
|
runs.
|
92
120
|
email:
|
93
121
|
- arturtrzop@gmail.com
|
94
|
-
executables:
|
122
|
+
executables:
|
123
|
+
- print_header.sh
|
95
124
|
extensions: []
|
96
125
|
extra_rdoc_files: []
|
97
126
|
files:
|
@@ -104,6 +133,7 @@ files:
|
|
104
133
|
- README.md
|
105
134
|
- Rakefile
|
106
135
|
- TODO.md
|
136
|
+
- bin/print_header.sh
|
107
137
|
- docs/images/logos/knapsack-@2.png
|
108
138
|
- docs/images/logos/knapsack-big.png
|
109
139
|
- docs/images/logos/knapsack-logo-@2.png
|
@@ -113,12 +143,15 @@ files:
|
|
113
143
|
- docs/images/with_knapsack.png
|
114
144
|
- docs/images/without_knapsack.png
|
115
145
|
- knapsack.gemspec
|
116
|
-
-
|
146
|
+
- knapsack_rspec_report.json
|
117
147
|
- lib/knapsack.rb
|
118
148
|
- lib/knapsack/adapters/base_adapter.rb
|
149
|
+
- lib/knapsack/adapters/cucumber_adapter.rb
|
119
150
|
- lib/knapsack/adapters/rspec_adapter.rb
|
120
151
|
- lib/knapsack/allocator.rb
|
121
|
-
- lib/knapsack/
|
152
|
+
- lib/knapsack/allocator_builder.rb
|
153
|
+
- lib/knapsack/config/env.rb
|
154
|
+
- lib/knapsack/config/tracker.rb
|
122
155
|
- lib/knapsack/distributors/base_distributor.rb
|
123
156
|
- lib/knapsack/distributors/leftover_distributor.rb
|
124
157
|
- lib/knapsack/distributors/report_distributor.rb
|
@@ -128,11 +161,15 @@ files:
|
|
128
161
|
- lib/knapsack/task_loader.rb
|
129
162
|
- lib/knapsack/tracker.rb
|
130
163
|
- lib/knapsack/version.rb
|
131
|
-
- lib/tasks/
|
164
|
+
- lib/tasks/knapsack_cucumber.rake
|
165
|
+
- lib/tasks/knapsack_rspec.rake
|
132
166
|
- spec/knapsack/adapters/base_adapter_spec.rb
|
167
|
+
- spec/knapsack/adapters/cucumber_adapter_spec.rb
|
133
168
|
- spec/knapsack/adapters/rspec_adapter_spec.rb
|
169
|
+
- spec/knapsack/allocator_builder_spec.rb
|
134
170
|
- spec/knapsack/allocator_spec.rb
|
135
|
-
- spec/knapsack/
|
171
|
+
- spec/knapsack/config/env_spec.rb
|
172
|
+
- spec/knapsack/config/tracker_spec.rb
|
136
173
|
- spec/knapsack/distributors/base_distributor_spec.rb
|
137
174
|
- spec/knapsack/distributors/leftover_distributor_spec.rb
|
138
175
|
- spec/knapsack/distributors/report_distributor_spec.rb
|
@@ -143,6 +180,7 @@ files:
|
|
143
180
|
- spec/knapsack/tracker_spec.rb
|
144
181
|
- spec/knapsack_spec.rb
|
145
182
|
- spec/spec_helper.rb
|
183
|
+
- spec/support/mocks/cucumber.rb
|
146
184
|
- spec/support/shared_examples/adapter.rb
|
147
185
|
- spec_examples/fast/1_spec.rb
|
148
186
|
- spec_examples/fast/2_spec.rb
|
@@ -181,12 +219,16 @@ rubyforge_project:
|
|
181
219
|
rubygems_version: 2.2.2
|
182
220
|
signing_key:
|
183
221
|
specification_version: 4
|
184
|
-
summary:
|
222
|
+
summary: Knapsack splits tests across CI nodes and makes sure that tests will run
|
223
|
+
comparable time on each node.
|
185
224
|
test_files:
|
186
225
|
- spec/knapsack/adapters/base_adapter_spec.rb
|
226
|
+
- spec/knapsack/adapters/cucumber_adapter_spec.rb
|
187
227
|
- spec/knapsack/adapters/rspec_adapter_spec.rb
|
228
|
+
- spec/knapsack/allocator_builder_spec.rb
|
188
229
|
- spec/knapsack/allocator_spec.rb
|
189
|
-
- spec/knapsack/
|
230
|
+
- spec/knapsack/config/env_spec.rb
|
231
|
+
- spec/knapsack/config/tracker_spec.rb
|
190
232
|
- spec/knapsack/distributors/base_distributor_spec.rb
|
191
233
|
- spec/knapsack/distributors/leftover_distributor_spec.rb
|
192
234
|
- spec/knapsack/distributors/report_distributor_spec.rb
|
@@ -197,4 +239,5 @@ test_files:
|
|
197
239
|
- spec/knapsack/tracker_spec.rb
|
198
240
|
- spec/knapsack_spec.rb
|
199
241
|
- spec/spec_helper.rb
|
242
|
+
- spec/support/mocks/cucumber.rb
|
200
243
|
- spec/support/shared_examples/adapter.rb
|
data/lib/knapsack/config.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Knapsack
|
2
|
-
class Config
|
3
|
-
class << self
|
4
|
-
def report_path
|
5
|
-
ENV['KNAPSACK_REPORT_PATH'] || 'knapsack_report.json'
|
6
|
-
end
|
7
|
-
|
8
|
-
def ci_node_total
|
9
|
-
ENV['CI_NODE_TOTAL'] || ENV['CIRCLE_NODE_TOTAL'] || ENV['SEMAPHORE_THREAD_COUNT'] || 1
|
10
|
-
end
|
11
|
-
|
12
|
-
def ci_node_index
|
13
|
-
ENV['CI_NODE_INDEX'] || ENV['CIRCLE_NODE_INDEX'] || semaphore_current_thread || 0
|
14
|
-
end
|
15
|
-
|
16
|
-
def spec_pattern
|
17
|
-
ENV['KNAPSACK_SPEC_PATTERN'] || 'spec/**/*_spec.rb'
|
18
|
-
end
|
19
|
-
|
20
|
-
def enable_time_offset_warning
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
def time_offset_in_seconds
|
25
|
-
30
|
26
|
-
end
|
27
|
-
|
28
|
-
def generate_report
|
29
|
-
ENV['KNAPSACK_GENERATE_REPORT'] || false
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def semaphore_current_thread
|
35
|
-
index = ENV['SEMAPHORE_CURRENT_THREAD']
|
36
|
-
index.to_i - 1 if index
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/tasks/knapsack.rake
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'knapsack'
|
2
|
-
|
3
|
-
namespace :knapsack do
|
4
|
-
task :rspec, [:rspec_args] do |t, args|
|
5
|
-
allocator = Knapsack::Allocator.new
|
6
|
-
rspec_args = args[:rspec_args]
|
7
|
-
|
8
|
-
puts
|
9
|
-
puts 'Report specs:'
|
10
|
-
puts allocator.report_node_specs
|
11
|
-
puts
|
12
|
-
puts 'Leftover specs:'
|
13
|
-
puts allocator.leftover_node_specs
|
14
|
-
puts
|
15
|
-
|
16
|
-
cmd = %Q[bundle exec rspec #{rspec_args} --default-path #{allocator.spec_dir} -- #{allocator.stringify_node_specs}]
|
17
|
-
|
18
|
-
exec(cmd)
|
19
|
-
end
|
20
|
-
end
|