knapsack_pro 0.44.0 → 0.45.0
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/README.md +18 -15
- data/lib/knapsack_pro/adapters/base_adapter.rb +5 -0
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +11 -0
- data/lib/knapsack_pro/hooks/queue.rb +33 -1
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +2 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/adapters/base_adapter_spec.rb +11 -0
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +11 -0
- data/spec/knapsack_pro/hooks/queue_spec.rb +52 -0
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e3898daf42db4b3cb0c746ad66f00ecda1048d
|
4
|
+
data.tar.gz: 5ed151190611d41bb925b93d9648385e5c55cbce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb27e6eb4038c8dd31009a6bee4d46379b68669a79cb6a2e61e7023ed61d390c2cbb13855e221a48f79a1d3c9388c91bc080515e9367a8bc4ef5da648b88a1e
|
7
|
+
data.tar.gz: 99c81386ae4c190c2c0d2bc07185b528f5c8be7c9937d419e2ab33f719c16688a1df321303750267723880fd745ab8d6f7c4bf29a15b43faff746b1602de9a8b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
* TODO
|
4
4
|
|
5
|
+
### 0.45.0
|
6
|
+
|
7
|
+
* Add before and after queue hooks
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/46
|
10
|
+
|
11
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.44.0...v0.45.0
|
12
|
+
|
5
13
|
### 0.44.0
|
6
14
|
|
7
15
|
* Add ability to set test_dir using an environment variable.
|
data/README.md
CHANGED
@@ -1188,11 +1188,15 @@ Knapsack Pro Queue Mode runs subset of test files from the work queue many times
|
|
1188
1188
|
```ruby
|
1189
1189
|
# spec_helper.rb or rails_helper.rb
|
1190
1190
|
|
1191
|
-
|
1192
|
-
|
1191
|
+
KnapsackPro::Hooks::Queue.before_queue do |queue_id|
|
1192
|
+
# executes before Queue Mode starts work
|
1193
|
+
Percy::Capybara.initialize_build
|
1194
|
+
end
|
1193
1195
|
|
1194
|
-
|
1195
|
-
|
1196
|
+
KnapsackPro::Hooks::Queue.after_queue do |queue_id|
|
1197
|
+
# executes after Queue Mode finishes work
|
1198
|
+
Percy::Capybara.finalize_build
|
1199
|
+
end
|
1196
1200
|
```
|
1197
1201
|
|
1198
1202
|
#### How to call `before(:suite)` and `after(:suite)` RSpec hooks only once in Queue Mode?
|
@@ -1202,18 +1206,17 @@ Knapsack Pro Queue Mode runs subset of test files from the work queue many times
|
|
1202
1206
|
```ruby
|
1203
1207
|
# spec_helper.rb or rails_helper.rb
|
1204
1208
|
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
# this will be called only once before the tests started on the CI node
|
1211
|
-
end
|
1212
|
-
end
|
1209
|
+
KnapsackPro::Hooks::Queue.before_queue do |queue_id|
|
1210
|
+
# This will be called only once before the tests started on the CI node.
|
1211
|
+
# It will be run inside of the RSpec before(:suite) block only once.
|
1212
|
+
# It means you will have access to whatever RSpec provides in the context of the before(:suite) block.
|
1213
|
+
end
|
1213
1214
|
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1215
|
+
KnapsackPro::Hooks::Queue.after_queue do |queue_id|
|
1216
|
+
# This will be called only once after test suite is completed.
|
1217
|
+
# Note this hook won't be called inside of RSpec after(:suite) block because
|
1218
|
+
# we are not able to determine which after(:suite) block will be called as the last one
|
1219
|
+
# due to the fact the Knapsack Pro Queue Mode allocates tests in dynamic way.
|
1217
1220
|
end
|
1218
1221
|
```
|
1219
1222
|
|
@@ -19,6 +19,7 @@ module KnapsackPro
|
|
19
19
|
|
20
20
|
if KnapsackPro::Config::Env.queue_recording_enabled?
|
21
21
|
KnapsackPro.logger.debug('Test suite time execution queue recording enabled.')
|
22
|
+
bind_before_queue_hook
|
22
23
|
bind_time_tracker
|
23
24
|
bind_save_queue_report
|
24
25
|
end
|
@@ -35,6 +36,10 @@ module KnapsackPro
|
|
35
36
|
def bind_save_queue_report
|
36
37
|
raise NotImplementedError
|
37
38
|
end
|
39
|
+
|
40
|
+
def bind_before_queue_hook
|
41
|
+
raise NotImplementedError
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
@@ -57,6 +57,17 @@ module KnapsackPro
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
61
|
+
def bind_before_queue_hook
|
62
|
+
::RSpec.configure do |config|
|
63
|
+
config.before(:suite) do
|
64
|
+
unless ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED']
|
65
|
+
KnapsackPro::Hooks::Queue.call_before_queue
|
66
|
+
ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] = 'true'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
60
71
|
end
|
61
72
|
|
62
73
|
# This is added to provide backwards compatibility
|
@@ -2,16 +2,41 @@ module KnapsackPro
|
|
2
2
|
module Hooks
|
3
3
|
class Queue
|
4
4
|
class << self
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :before_queue,
|
6
|
+
:after_subset_queue,
|
7
|
+
:after_queue
|
8
|
+
|
9
|
+
def reset_before_queue
|
10
|
+
@before_queue = nil
|
11
|
+
end
|
6
12
|
|
7
13
|
def reset_after_subset_queue
|
8
14
|
@after_subset_queue = nil
|
9
15
|
end
|
10
16
|
|
17
|
+
def reset_after_queue
|
18
|
+
@after_queue = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def before_queue(&block)
|
22
|
+
@before_queue ||= block
|
23
|
+
end
|
24
|
+
|
11
25
|
def after_subset_queue(&block)
|
12
26
|
@after_subset_queue ||= block
|
13
27
|
end
|
14
28
|
|
29
|
+
def after_queue(&block)
|
30
|
+
@after_queue ||= block
|
31
|
+
end
|
32
|
+
|
33
|
+
def call_before_queue
|
34
|
+
return unless before_queue
|
35
|
+
before_queue.call(
|
36
|
+
KnapsackPro::Config::Env.queue_id
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
15
40
|
def call_after_subset_queue
|
16
41
|
return unless after_subset_queue
|
17
42
|
after_subset_queue.call(
|
@@ -19,6 +44,13 @@ module KnapsackPro
|
|
19
44
|
KnapsackPro::Config::Env.subset_queue_id
|
20
45
|
)
|
21
46
|
end
|
47
|
+
|
48
|
+
def call_after_queue
|
49
|
+
return unless after_queue
|
50
|
+
after_queue.call(
|
51
|
+
KnapsackPro::Config::Env.queue_id
|
52
|
+
)
|
53
|
+
end
|
22
54
|
end
|
23
55
|
end
|
24
56
|
end
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -48,6 +48,7 @@ describe KnapsackPro::Adapters::BaseAdapter do
|
|
48
48
|
let(:queue_recording_enabled?) { true }
|
49
49
|
|
50
50
|
before do
|
51
|
+
allow(subject).to receive(:bind_before_queue_hook)
|
51
52
|
allow(subject).to receive(:bind_time_tracker)
|
52
53
|
allow(subject).to receive(:bind_save_queue_report)
|
53
54
|
end
|
@@ -57,6 +58,7 @@ describe KnapsackPro::Adapters::BaseAdapter do
|
|
57
58
|
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
58
59
|
expect(logger).to receive(:debug).with('Test suite time execution queue recording enabled.')
|
59
60
|
end
|
61
|
+
it { expect(subject).to receive(:bind_before_queue_hook) }
|
60
62
|
it { expect(subject).to receive(:bind_time_tracker) }
|
61
63
|
it { expect(subject).to receive(:bind_save_queue_report) }
|
62
64
|
end
|
@@ -65,6 +67,7 @@ describe KnapsackPro::Adapters::BaseAdapter do
|
|
65
67
|
it { expect(subject).not_to receive(:bind_time_tracker) }
|
66
68
|
it { expect(subject).not_to receive(:bind_save_report) }
|
67
69
|
it { expect(subject).not_to receive(:bind_save_queue_report) }
|
70
|
+
it { expect(subject).not_to receive(:bind_before_queue_hook) }
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
@@ -91,4 +94,12 @@ describe KnapsackPro::Adapters::BaseAdapter do
|
|
91
94
|
}.to raise_error(NotImplementedError)
|
92
95
|
end
|
93
96
|
end
|
97
|
+
|
98
|
+
describe '#bind_before_queue_hook' do
|
99
|
+
it do
|
100
|
+
expect {
|
101
|
+
subject.bind_before_queue_hook
|
102
|
+
}.to raise_error(NotImplementedError)
|
103
|
+
end
|
104
|
+
end
|
94
105
|
end
|
@@ -123,5 +123,16 @@ describe KnapsackPro::Adapters::RSpecAdapter do
|
|
123
123
|
subject.bind_save_queue_report
|
124
124
|
end
|
125
125
|
end
|
126
|
+
|
127
|
+
describe '#bind_before_queue_hook' do
|
128
|
+
it do
|
129
|
+
expect(config).to receive(:before).with(:suite).and_yield
|
130
|
+
expect(::RSpec).to receive(:configure).and_yield(config)
|
131
|
+
|
132
|
+
expect(KnapsackPro::Hooks::Queue).to receive(:call_before_queue)
|
133
|
+
|
134
|
+
subject.bind_before_queue_hook
|
135
|
+
end
|
136
|
+
end
|
126
137
|
end
|
127
138
|
end
|
@@ -1,4 +1,30 @@
|
|
1
1
|
describe KnapsackPro::Hooks::Queue do
|
2
|
+
describe '.call_before_queue' do
|
3
|
+
subject { described_class.call_before_queue }
|
4
|
+
|
5
|
+
context 'when callback is not set' do
|
6
|
+
before do
|
7
|
+
described_class.reset_before_queue
|
8
|
+
end
|
9
|
+
|
10
|
+
it { should be_nil }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when callback is set' do
|
14
|
+
let(:queue_id) { double }
|
15
|
+
|
16
|
+
before do
|
17
|
+
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
18
|
+
|
19
|
+
described_class.before_queue do |q_id|
|
20
|
+
[:fake_value, q_id]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it { should eq [:fake_value, queue_id] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
2
28
|
describe '.call_after_subset_queue' do
|
3
29
|
subject { described_class.call_after_subset_queue }
|
4
30
|
|
@@ -26,4 +52,30 @@ describe KnapsackPro::Hooks::Queue do
|
|
26
52
|
it { should eq [:fake_value, queue_id, subset_queue_id] }
|
27
53
|
end
|
28
54
|
end
|
55
|
+
|
56
|
+
describe '.call_after_queue' do
|
57
|
+
subject { described_class.call_after_queue }
|
58
|
+
|
59
|
+
context 'when callback is not set' do
|
60
|
+
before do
|
61
|
+
described_class.reset_after_queue
|
62
|
+
end
|
63
|
+
|
64
|
+
it { should be_nil }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when callback is set' do
|
68
|
+
let(:queue_id) { double }
|
69
|
+
|
70
|
+
before do
|
71
|
+
expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
|
72
|
+
|
73
|
+
described_class.after_queue do |q_id|
|
74
|
+
[:fake_value, q_id]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it { should eq [:fake_value, queue_id] }
|
79
|
+
end
|
80
|
+
end
|
29
81
|
end
|
@@ -111,6 +111,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
111
111
|
it do
|
112
112
|
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
113
113
|
expect(KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension).to receive(:print_summary)
|
114
|
+
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
114
115
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
115
116
|
expect(described_class).to receive(:exit).with(exitstatus)
|
116
117
|
|
@@ -124,6 +125,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
124
125
|
it do
|
125
126
|
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
126
127
|
expect(KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension).to receive(:print_summary)
|
128
|
+
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
127
129
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
128
130
|
expect(described_class).to receive(:exit).with(exit_code)
|
129
131
|
|
@@ -136,6 +138,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
136
138
|
let(:test_file_paths) { [] }
|
137
139
|
|
138
140
|
it do
|
141
|
+
expect(KnapsackPro::Hooks::Queue).to receive(:call_after_queue)
|
139
142
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
140
143
|
expect(described_class).to receive(:exit).with(exitstatus)
|
141
144
|
|
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: 0.
|
4
|
+
version: 0.45.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|