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,57 +1,56 @@
|
|
1
1
|
describe Knapsack::Allocator do
|
2
|
-
let(:
|
2
|
+
let(:test_file_pattern) { nil }
|
3
3
|
let(:args) do
|
4
4
|
{
|
5
5
|
ci_node_total: nil,
|
6
6
|
ci_node_index: nil,
|
7
|
-
|
7
|
+
test_file_pattern: test_file_pattern,
|
8
8
|
report: nil
|
9
9
|
}
|
10
10
|
end
|
11
11
|
let(:report_distributor) { instance_double(Knapsack::Distributors::ReportDistributor) }
|
12
12
|
let(:leftover_distributor) { instance_double(Knapsack::Distributors::LeftoverDistributor) }
|
13
|
-
let(:
|
14
|
-
let(:
|
15
|
-
let(:
|
13
|
+
let(:report_tests) { ['a_spec.rb', 'b_spec.rb'] }
|
14
|
+
let(:leftover_tests) { ['c_spec.rb', 'd_spec.rb'] }
|
15
|
+
let(:node_tests) { report_tests + leftover_tests }
|
16
16
|
let(:allocator) { described_class.new(args) }
|
17
17
|
|
18
18
|
before do
|
19
19
|
expect(Knapsack::Distributors::ReportDistributor).to receive(:new).with(args).and_return(report_distributor)
|
20
20
|
expect(Knapsack::Distributors::LeftoverDistributor).to receive(:new).with(args).and_return(leftover_distributor)
|
21
|
-
allow(report_distributor).to receive(:
|
22
|
-
allow(leftover_distributor).to receive(:
|
21
|
+
allow(report_distributor).to receive(:tests_for_current_node).and_return(report_tests)
|
22
|
+
allow(leftover_distributor).to receive(:tests_for_current_node).and_return(leftover_tests)
|
23
23
|
end
|
24
24
|
|
25
|
-
describe '#
|
26
|
-
subject { allocator.
|
27
|
-
it { should eql
|
25
|
+
describe '#report_node_tests' do
|
26
|
+
subject { allocator.report_node_tests }
|
27
|
+
it { should eql report_tests }
|
28
28
|
end
|
29
29
|
|
30
|
-
describe '#
|
31
|
-
subject { allocator.
|
32
|
-
it { should eql
|
30
|
+
describe '#leftover_node_tests' do
|
31
|
+
subject { allocator.leftover_node_tests }
|
32
|
+
it { should eql leftover_tests }
|
33
33
|
end
|
34
34
|
|
35
|
-
describe '#
|
36
|
-
subject { allocator.
|
37
|
-
it { should eql
|
35
|
+
describe '#node_tests' do
|
36
|
+
subject { allocator.node_tests }
|
37
|
+
it { should eql node_tests }
|
38
38
|
end
|
39
39
|
|
40
|
-
describe '#
|
41
|
-
subject { allocator.
|
42
|
-
it { should eql
|
40
|
+
describe '#stringify_node_tests' do
|
41
|
+
subject { allocator.stringify_node_tests }
|
42
|
+
it { should eql node_tests.join(' ') }
|
43
43
|
end
|
44
44
|
|
45
|
-
describe '#
|
46
|
-
|
45
|
+
describe '#test_dir' do
|
46
|
+
let(:test_file_pattern) { "test_dir/**/*_spec.rb" }
|
47
47
|
|
48
|
-
|
49
|
-
let(:spec_pattern) { "spec_dir/**/*_spec.rb" }
|
50
|
-
it { should eql 'spec_dir/' }
|
51
|
-
end
|
48
|
+
subject { allocator.test_dir }
|
52
49
|
|
53
|
-
|
54
|
-
|
50
|
+
before do
|
51
|
+
expect(report_distributor).to receive(:test_file_pattern).and_return(test_file_pattern)
|
55
52
|
end
|
53
|
+
|
54
|
+
it { should eql 'test_dir/' }
|
56
55
|
end
|
57
56
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
describe Knapsack::Config do
|
1
|
+
describe Knapsack::Config::Env do
|
2
2
|
describe '.report_path' do
|
3
3
|
subject { described_class.report_path }
|
4
4
|
|
5
5
|
context 'when ENV exists' do
|
6
|
-
let(:report_path) { '
|
6
|
+
let(:report_path) { 'knapsack_custom_report.json' }
|
7
7
|
before { stub_const("ENV", { 'KNAPSACK_REPORT_PATH' => report_path }) }
|
8
8
|
it { should eql report_path }
|
9
9
|
end
|
10
10
|
|
11
11
|
context "when ENV doesn't exist" do
|
12
|
-
it { should
|
12
|
+
it { should be_nil }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -63,40 +63,17 @@ describe Knapsack::Config do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
describe '.
|
67
|
-
subject { described_class.
|
66
|
+
describe '.test_file_pattern' do
|
67
|
+
subject { described_class.test_file_pattern }
|
68
68
|
|
69
69
|
context 'when ENV exists' do
|
70
|
-
let(:
|
71
|
-
before { stub_const("ENV", { '
|
72
|
-
it { should eql
|
70
|
+
let(:test_file_pattern) { 'custom_spec/**/*_spec.rb' }
|
71
|
+
before { stub_const("ENV", { 'KNAPSACK_TEST_FILE_PATTERN' => test_file_pattern }) }
|
72
|
+
it { should eql test_file_pattern }
|
73
73
|
end
|
74
74
|
|
75
75
|
context "when ENV doesn't exist" do
|
76
|
-
it { should
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '.enable_time_offset_warning' do
|
81
|
-
subject { described_class.enable_time_offset_warning }
|
82
|
-
it { should be true }
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '.time_offset_in_seconds' do
|
86
|
-
subject { described_class.time_offset_in_seconds }
|
87
|
-
it { should eql 30 }
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '.generate_report' do
|
91
|
-
subject { described_class.generate_report }
|
92
|
-
|
93
|
-
context 'when ENV exists' do
|
94
|
-
before { stub_const("ENV", { 'KNAPSACK_GENERATE_REPORT' => true }) }
|
95
|
-
it { should be true }
|
96
|
-
end
|
97
|
-
|
98
|
-
context "when ENV doesn't exist" do
|
99
|
-
it { should be false }
|
76
|
+
it { should be_nil }
|
100
77
|
end
|
101
78
|
end
|
102
79
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe Knapsack::Config::Tracker do
|
2
|
+
describe '.enable_time_offset_warning' do
|
3
|
+
subject { described_class.enable_time_offset_warning }
|
4
|
+
it { should be true }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe '.time_offset_in_seconds' do
|
8
|
+
subject { described_class.time_offset_in_seconds }
|
9
|
+
it { should eql 30 }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.generate_report' do
|
13
|
+
subject { described_class.generate_report }
|
14
|
+
|
15
|
+
context 'when ENV exists' do
|
16
|
+
before { stub_const("ENV", { 'KNAPSACK_GENERATE_REPORT' => true }) }
|
17
|
+
it { should be true }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when ENV doesn't exist" do
|
21
|
+
it { should be false }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
describe Knapsack::Distributors::BaseDistributor do
|
2
|
-
let(:
|
3
|
-
let(:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
instance_double(Knapsack::Report, open: default_report)
|
2
|
+
let(:report) { { 'a_spec.rb' => 1.0 } }
|
3
|
+
let(:default_args) do
|
4
|
+
{
|
5
|
+
report: report,
|
6
|
+
test_file_pattern: 'spec/**/*_spec.rb',
|
7
|
+
ci_node_total: '1',
|
8
|
+
ci_node_index: '0'
|
10
9
|
}
|
11
10
|
end
|
11
|
+
let(:args) { default_args.merge(custom_args) }
|
12
|
+
let(:custom_args) { {} }
|
13
|
+
let(:distributor) { described_class.new(args) }
|
12
14
|
|
13
15
|
describe '#report' do
|
14
16
|
subject { distributor.report }
|
15
17
|
|
16
18
|
context 'when report is given' do
|
17
|
-
let(:report) { { 'a_spec.rb' => 2.0 } }
|
18
|
-
let(:args) { { report: report } }
|
19
|
-
|
20
19
|
it { should eql(report) }
|
21
20
|
end
|
22
21
|
|
23
22
|
context 'when report is not given' do
|
24
|
-
|
23
|
+
let(:custom_args) { { report: nil } }
|
24
|
+
it { expect { subject }.to raise_error('Missing report') }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,13 +29,12 @@ describe Knapsack::Distributors::BaseDistributor do
|
|
29
29
|
subject { distributor.ci_node_total }
|
30
30
|
|
31
31
|
context 'when ci_node_total is given' do
|
32
|
-
|
33
|
-
|
34
|
-
it { should eql 4 }
|
32
|
+
it { should eql 1 }
|
35
33
|
end
|
36
34
|
|
37
35
|
context 'when ci_node_total is not given' do
|
38
|
-
|
36
|
+
let(:custom_args) { { ci_node_total: nil } }
|
37
|
+
it { expect { subject }.to raise_error('Missing ci_node_total') }
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
@@ -43,43 +42,31 @@ describe Knapsack::Distributors::BaseDistributor do
|
|
43
42
|
subject { distributor.ci_node_index }
|
44
43
|
|
45
44
|
context 'when ci_node_index is given' do
|
46
|
-
|
47
|
-
|
48
|
-
it { should eql 3 }
|
45
|
+
it { should eql 0 }
|
49
46
|
end
|
50
47
|
|
51
48
|
context 'when ci_node_index is not given' do
|
52
|
-
|
49
|
+
let(:custom_args) { { ci_node_index: nil } }
|
50
|
+
it { expect { subject }.to raise_error('Missing ci_node_index') }
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
describe '#
|
57
|
-
let(:
|
54
|
+
describe '#tests_for_current_node' do
|
55
|
+
let(:custom_args) do
|
58
56
|
{
|
59
57
|
ci_node_total: 3,
|
60
58
|
ci_node_index: ci_node_index
|
61
59
|
}
|
62
60
|
end
|
63
|
-
let(:
|
61
|
+
let(:ci_node_index) { 2 }
|
62
|
+
let(:tests) { double }
|
64
63
|
|
65
|
-
subject { distributor.
|
64
|
+
subject { distributor.tests_for_current_node }
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
it do
|
71
|
-
expect(distributor).to receive(:specs_for_node).with(0).and_return(specs)
|
72
|
-
expect(subject).to eql specs
|
73
|
-
end
|
66
|
+
before do
|
67
|
+
expect(distributor).to receive(:tests_for_node).with(ci_node_index).and_return(tests)
|
74
68
|
end
|
75
69
|
|
76
|
-
|
77
|
-
let(:ci_node_index) { 2 }
|
78
|
-
|
79
|
-
it do
|
80
|
-
expect(distributor).to receive(:specs_for_node).with(ci_node_index).and_return(specs)
|
81
|
-
expect(subject).to eql specs
|
82
|
-
end
|
83
|
-
end
|
70
|
+
it { should eql tests }
|
84
71
|
end
|
85
72
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
describe Knapsack::Distributors::LeftoverDistributor do
|
2
|
-
let(:
|
3
|
-
let(:default_report) do
|
2
|
+
let(:report) do
|
4
3
|
{
|
5
4
|
'a_spec.rb' => 1.0,
|
6
5
|
'b_spec.rb' => 1.5,
|
@@ -8,40 +7,59 @@ describe Knapsack::Distributors::LeftoverDistributor do
|
|
8
7
|
'd_spec.rb' => 2.5,
|
9
8
|
}
|
10
9
|
end
|
11
|
-
|
12
|
-
let(:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
let(:test_file_pattern) { 'spec/**/*_spec.rb' }
|
11
|
+
let(:default_args) do
|
12
|
+
{
|
13
|
+
report: report,
|
14
|
+
test_file_pattern: test_file_pattern,
|
15
|
+
ci_node_total: '1',
|
16
|
+
ci_node_index: '0'
|
17
17
|
}
|
18
18
|
end
|
19
|
+
let(:args) { default_args.merge(custom_args) }
|
20
|
+
let(:custom_args) { {} }
|
21
|
+
let(:distributor) { described_class.new(args) }
|
19
22
|
|
20
|
-
describe '#
|
21
|
-
subject { distributor.
|
23
|
+
describe '#report_tests' do
|
24
|
+
subject { distributor.report_tests }
|
22
25
|
it { should eql ['a_spec.rb', 'b_spec.rb', 'c_spec.rb', 'd_spec.rb'] }
|
23
26
|
end
|
24
27
|
|
25
|
-
describe '#
|
26
|
-
subject { distributor.
|
28
|
+
describe '#all_tests' do
|
29
|
+
subject { distributor.all_tests }
|
27
30
|
|
28
|
-
context 'when
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
context 'when given test_file_pattern' do
|
32
|
+
context 'spec/**/*_spec.rb' do
|
33
|
+
it { should_not be_empty }
|
34
|
+
it { should include 'spec/knapsack/tracker_spec.rb' }
|
35
|
+
it { should include 'spec/knapsack/adapters/rspec_adapter_spec.rb' }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'spec_examples/**/*_spec.rb' do
|
39
|
+
let(:test_file_pattern) { 'spec_examples/**/*_spec.rb' }
|
40
|
+
|
41
|
+
it { should_not be_empty }
|
42
|
+
it { should include 'spec_examples/fast/1_spec.rb' }
|
43
|
+
it { should include 'spec_examples/leftover/a_spec.rb' }
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
|
-
context 'when fake
|
35
|
-
let(:
|
47
|
+
context 'when fake test_file_pattern' do
|
48
|
+
let(:test_file_pattern) { 'fake_pattern' }
|
36
49
|
it { should be_empty }
|
37
50
|
end
|
51
|
+
|
52
|
+
context 'when missing test_file_pattern' do
|
53
|
+
let(:test_file_pattern) { nil }
|
54
|
+
it { expect { subject }.to raise_error('Missing test_file_pattern') }
|
55
|
+
end
|
38
56
|
end
|
39
57
|
|
40
|
-
describe '#
|
41
|
-
subject { distributor.
|
58
|
+
describe '#leftover_tests' do
|
59
|
+
subject { distributor.leftover_tests }
|
42
60
|
|
43
61
|
before do
|
44
|
-
expect(distributor).to receive(:
|
62
|
+
expect(distributor).to receive(:all_tests).and_return([
|
45
63
|
'a_spec.rb',
|
46
64
|
'b_spec.rb',
|
47
65
|
'c_spec.rb',
|
@@ -55,8 +73,8 @@ describe Knapsack::Distributors::LeftoverDistributor do
|
|
55
73
|
end
|
56
74
|
|
57
75
|
context do
|
58
|
-
let(:
|
59
|
-
let(:
|
76
|
+
let(:custom_args) { { ci_node_total: 3 } }
|
77
|
+
let(:leftover_tests) {[
|
60
78
|
'a_spec.rb',
|
61
79
|
'b_spec.rb',
|
62
80
|
'c_spec.rb',
|
@@ -67,16 +85,16 @@ describe Knapsack::Distributors::LeftoverDistributor do
|
|
67
85
|
]}
|
68
86
|
|
69
87
|
before do
|
70
|
-
expect(distributor).to receive(:
|
88
|
+
expect(distributor).to receive(:leftover_tests).and_return(leftover_tests)
|
71
89
|
end
|
72
90
|
|
73
|
-
describe '#
|
91
|
+
describe '#assign_test_files_to_node' do
|
74
92
|
before do
|
75
|
-
distributor.
|
93
|
+
distributor.assign_test_files_to_node
|
76
94
|
end
|
77
95
|
|
78
96
|
it do
|
79
|
-
expect(distributor.
|
97
|
+
expect(distributor.node_tests[0]).to eql([
|
80
98
|
'a_spec.rb',
|
81
99
|
'd_spec.rb',
|
82
100
|
'g_spec.rb',
|
@@ -84,23 +102,23 @@ describe Knapsack::Distributors::LeftoverDistributor do
|
|
84
102
|
end
|
85
103
|
|
86
104
|
it do
|
87
|
-
expect(distributor.
|
105
|
+
expect(distributor.node_tests[1]).to eql([
|
88
106
|
'b_spec.rb',
|
89
107
|
'e_spec.rb',
|
90
108
|
])
|
91
109
|
end
|
92
110
|
|
93
111
|
it do
|
94
|
-
expect(distributor.
|
112
|
+
expect(distributor.node_tests[2]).to eql([
|
95
113
|
'c_spec.rb',
|
96
114
|
'f_spec.rb',
|
97
115
|
])
|
98
116
|
end
|
99
117
|
end
|
100
118
|
|
101
|
-
describe '#
|
119
|
+
describe '#tests_for_node' do
|
102
120
|
it do
|
103
|
-
expect(distributor.
|
121
|
+
expect(distributor.tests_for_node(1)).to eql([
|
104
122
|
'b_spec.rb',
|
105
123
|
'e_spec.rb',
|
106
124
|
])
|
@@ -1,14 +1,16 @@
|
|
1
1
|
describe Knapsack::Distributors::ReportDistributor do
|
2
|
-
let(:
|
3
|
-
let(:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
instance_double(Knapsack::Report, open: default_report)
|
2
|
+
let(:report) { { 'a_spec.rb' => 1.0 } }
|
3
|
+
let(:default_args) do
|
4
|
+
{
|
5
|
+
report: report,
|
6
|
+
test_file_pattern: 'spec/**/*_spec.rb',
|
7
|
+
ci_node_total: '1',
|
8
|
+
ci_node_index: '0'
|
10
9
|
}
|
11
10
|
end
|
11
|
+
let(:args) { default_args.merge(custom_args) }
|
12
|
+
let(:custom_args) { {} }
|
13
|
+
let(:distributor) { described_class.new(args) }
|
12
14
|
|
13
15
|
describe '#sorted_report' do
|
14
16
|
subject { distributor.sorted_report }
|
@@ -23,7 +25,6 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
23
25
|
'b_spec.rb' => 1.5,
|
24
26
|
}
|
25
27
|
end
|
26
|
-
let(:args) { { report: report } }
|
27
28
|
|
28
29
|
it do
|
29
30
|
should eql([
|
@@ -37,16 +38,8 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
describe '#
|
41
|
-
subject { distributor.
|
42
|
-
|
43
|
-
before do
|
44
|
-
expect(distributor).to receive(:all_specs).exactly(6).times.and_return([
|
45
|
-
'b_spec.rb',
|
46
|
-
'd_spec.rb',
|
47
|
-
'f_spec.rb',
|
48
|
-
])
|
49
|
-
end
|
41
|
+
describe '#sorted_report_with_existing_tests' do
|
42
|
+
subject { distributor.sorted_report_with_existing_tests }
|
50
43
|
|
51
44
|
let(:report) do
|
52
45
|
{
|
@@ -58,7 +51,14 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
58
51
|
'b_spec.rb' => 1.5,
|
59
52
|
}
|
60
53
|
end
|
61
|
-
|
54
|
+
|
55
|
+
before do
|
56
|
+
expect(distributor).to receive(:all_tests).exactly(6).times.and_return([
|
57
|
+
'b_spec.rb',
|
58
|
+
'd_spec.rb',
|
59
|
+
'f_spec.rb',
|
60
|
+
])
|
61
|
+
end
|
62
62
|
|
63
63
|
it do
|
64
64
|
should eql([
|
@@ -77,10 +77,9 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
77
77
|
'c_spec.rb' => 1.5,
|
78
78
|
}
|
79
79
|
end
|
80
|
-
let(:args) { { report: report } }
|
81
80
|
|
82
81
|
before do
|
83
|
-
allow(distributor).to receive(:
|
82
|
+
allow(distributor).to receive(:all_tests).and_return(report.keys)
|
84
83
|
end
|
85
84
|
|
86
85
|
describe '#total_time_execution' do
|
@@ -104,7 +103,7 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
104
103
|
|
105
104
|
describe '#node_time_execution' do
|
106
105
|
subject { distributor.node_time_execution }
|
107
|
-
let(:
|
106
|
+
let(:custom_args) { { ci_node_total: 4 } }
|
108
107
|
it { should eql 1.375 }
|
109
108
|
end
|
110
109
|
end
|
@@ -122,35 +121,30 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
122
121
|
'b_spec.rb' => 1.5,
|
123
122
|
}
|
124
123
|
end
|
125
|
-
let(:
|
126
|
-
{
|
127
|
-
report: report,
|
128
|
-
ci_node_total: 3,
|
129
|
-
}
|
130
|
-
end
|
124
|
+
let(:custom_args) { { ci_node_total: 3 } }
|
131
125
|
|
132
126
|
before do
|
133
|
-
allow(distributor).to receive(:
|
127
|
+
allow(distributor).to receive(:all_tests).and_return(report.keys)
|
134
128
|
end
|
135
129
|
|
136
|
-
describe '#
|
137
|
-
before { distributor.
|
130
|
+
describe '#assign_test_files_to_node' do
|
131
|
+
before { distributor.assign_test_files_to_node }
|
138
132
|
|
139
133
|
it do
|
140
|
-
expect(distributor.
|
134
|
+
expect(distributor.node_tests[0]).to eql({
|
141
135
|
:node_index => 0,
|
142
136
|
:time_left => -0.5,
|
143
|
-
:
|
137
|
+
:test_files_with_time => [
|
144
138
|
["g_spec.rb", 9.0]
|
145
139
|
]
|
146
140
|
})
|
147
141
|
end
|
148
142
|
|
149
143
|
it do
|
150
|
-
expect(distributor.
|
144
|
+
expect(distributor.node_tests[1]).to eql({
|
151
145
|
:node_index => 1,
|
152
146
|
:time_left => 0.0,
|
153
|
-
:
|
147
|
+
:test_files_with_time => [
|
154
148
|
["f_spec.rb", 3.5],
|
155
149
|
["d_spec.rb", 2.5],
|
156
150
|
["a_spec.rb", 1.0],
|
@@ -160,10 +154,10 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
160
154
|
end
|
161
155
|
|
162
156
|
it do
|
163
|
-
expect(distributor.
|
157
|
+
expect(distributor.node_tests[2]).to eql({
|
164
158
|
:node_index => 2,
|
165
159
|
:time_left => 0.5,
|
166
|
-
:
|
160
|
+
:test_files_with_time => [
|
167
161
|
["h_spec.rb", 3.0],
|
168
162
|
["c_spec.rb", 2.0],
|
169
163
|
["i_spec.rb", 3.0]
|
@@ -172,10 +166,10 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
172
166
|
end
|
173
167
|
end
|
174
168
|
|
175
|
-
describe '#
|
169
|
+
describe '#tests_for_node' do
|
176
170
|
context 'when node exists' do
|
177
171
|
it do
|
178
|
-
expect(distributor.
|
172
|
+
expect(distributor.tests_for_node(1)).to eql([
|
179
173
|
'f_spec.rb',
|
180
174
|
'd_spec.rb',
|
181
175
|
'a_spec.rb',
|
@@ -185,7 +179,7 @@ describe Knapsack::Distributors::ReportDistributor do
|
|
185
179
|
end
|
186
180
|
|
187
181
|
context "when node doesn't exist" do
|
188
|
-
it { expect(distributor.
|
182
|
+
it { expect(distributor.tests_for_node(42)).to be_nil }
|
189
183
|
end
|
190
184
|
end
|
191
185
|
end
|