knapsack_pro 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +151 -2
  4. data/bin/knapsack_pro +1 -0
  5. data/knapsack_pro.gemspec +1 -1
  6. data/lib/knapsack_pro.rb +8 -0
  7. data/lib/knapsack_pro/adapters/base_adapter.rb +10 -0
  8. data/lib/knapsack_pro/adapters/rspec_adapter.rb +8 -0
  9. data/lib/knapsack_pro/allocator.rb +28 -14
  10. data/lib/knapsack_pro/allocator_builder.rb +1 -29
  11. data/lib/knapsack_pro/base_allocator_builder.rb +35 -0
  12. data/lib/knapsack_pro/client/api/v1/queues.rb +27 -0
  13. data/lib/knapsack_pro/config/ci/base.rb +3 -0
  14. data/lib/knapsack_pro/config/ci/buildkite.rb +4 -0
  15. data/lib/knapsack_pro/config/ci/circle.rb +4 -1
  16. data/lib/knapsack_pro/config/ci/semaphore.rb +4 -0
  17. data/lib/knapsack_pro/config/ci/snap_ci.rb +4 -0
  18. data/lib/knapsack_pro/config/ci/travis.rb +4 -0
  19. data/lib/knapsack_pro/config/env.rb +22 -0
  20. data/lib/knapsack_pro/config/env_generator.rb +19 -0
  21. data/lib/knapsack_pro/queue_allocator.rb +52 -0
  22. data/lib/knapsack_pro/queue_allocator_builder.rb +13 -0
  23. data/lib/knapsack_pro/report.rb +35 -0
  24. data/lib/knapsack_pro/runners/queue/base_runner.rb +34 -0
  25. data/lib/knapsack_pro/runners/queue/rspec_runner.rb +42 -0
  26. data/lib/knapsack_pro/task_loader.rb +1 -1
  27. data/lib/knapsack_pro/version.rb +1 -1
  28. data/lib/tasks/queue/rspec.rake +9 -0
  29. data/lib/tasks/salt.rake +0 -2
  30. data/spec/knapsack_pro/adapters/base_adapter_spec.rb +39 -8
  31. data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +11 -0
  32. data/spec/knapsack_pro/allocator_builder_spec.rb +2 -12
  33. data/spec/knapsack_pro/base_allocator_builder_spec.rb +22 -0
  34. data/spec/knapsack_pro/client/api/v1/queues_spec.rb +42 -0
  35. data/spec/knapsack_pro/config/ci/base_spec.rb +1 -0
  36. data/spec/knapsack_pro/config/ci/buildkite_spec.rb +13 -0
  37. data/spec/knapsack_pro/config/ci/circle_spec.rb +13 -0
  38. data/spec/knapsack_pro/config/ci/semaphore_spec.rb +13 -0
  39. data/spec/knapsack_pro/config/ci/snap_ci_spec.rb +13 -0
  40. data/spec/knapsack_pro/config/ci/travis_spec.rb +13 -0
  41. data/spec/knapsack_pro/config/env_generator_spec.rb +52 -0
  42. data/spec/knapsack_pro/config/env_spec.rb +90 -0
  43. data/spec/knapsack_pro/queue_allocator_builder_spec.rb +38 -0
  44. data/spec/knapsack_pro/queue_allocator_spec.rb +85 -0
  45. data/spec/knapsack_pro/report_spec.rb +69 -0
  46. data/spec/knapsack_pro/runners/queue/base_runner_spec.rb +67 -0
  47. data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +118 -0
  48. metadata +26 -4
@@ -2,11 +2,80 @@ describe KnapsackPro::Report do
2
2
  describe '.save' do
3
3
  subject { described_class.save }
4
4
 
5
+ it do
6
+ test_files = double
7
+ tracker = instance_double(KnapsackPro::Tracker, to_a: test_files)
8
+ expect(KnapsackPro).to receive(:tracker).and_return(tracker)
9
+ expect(described_class).to receive(:create_build_subset).with(test_files)
10
+
11
+ subject
12
+ end
13
+ end
14
+
15
+ describe '.save_subset_queue_to_file' do
16
+ let(:fake_path) { SecureRandom.uuid }
17
+
18
+ subject { described_class.save_subset_queue_to_file }
19
+
5
20
  before do
21
+ test_files = [{path: fake_path}]
6
22
  tracker = instance_double(KnapsackPro::Tracker, to_a: test_files)
7
23
  expect(KnapsackPro).to receive(:tracker).and_return(tracker)
24
+
25
+ subset_queue_id = 'fake-subset-queue-id'
26
+ expect(KnapsackPro::Config::Env).to receive(:subset_queue_id).and_return(subset_queue_id)
27
+
28
+ queue_id = 'fake-queue-id'
29
+ expect(KnapsackPro::Config::Env).to receive(:queue_id).twice.and_return(queue_id)
8
30
  end
9
31
 
32
+ it do
33
+ subject
34
+
35
+ expect(
36
+ JSON.parse(
37
+ File.read('tmp/knapsack_pro/queue/fake-queue-id/fake-subset-queue-id.json')
38
+ )
39
+ ).to eq([
40
+ { 'path' => fake_path }
41
+ ])
42
+ end
43
+ end
44
+
45
+ describe '.save_node_queue_to_api' do
46
+ let(:json_test_file_a_path) { double }
47
+ let(:json_test_file_a) { [{ 'path' => 'a_spec.rb' }] }
48
+
49
+ let(:json_test_file_b_path) { double }
50
+ let(:json_test_file_b) { [{ 'path' => 'b_spec.rb' }] }
51
+
52
+ subject { described_class.save_node_queue_to_api }
53
+
54
+ before do
55
+ queue_id = 'fake-queue-id'
56
+ expect(KnapsackPro::Config::Env).to receive(:queue_id).and_return(queue_id)
57
+
58
+ expect(Dir).to receive(:glob).with('tmp/knapsack_pro/queue/fake-queue-id/*.json').and_return([
59
+ json_test_file_a_path,
60
+ json_test_file_b_path
61
+ ])
62
+
63
+ expect(File).to receive(:read).with(json_test_file_a_path).and_return(json_test_file_a.to_json)
64
+ expect(File).to receive(:read).with(json_test_file_b_path).and_return(json_test_file_b.to_json)
65
+ end
66
+
67
+ it do
68
+ expect(described_class).to receive(:create_build_subset).with(
69
+ json_test_file_a + json_test_file_b
70
+ )
71
+
72
+ subject
73
+ end
74
+ end
75
+
76
+ describe '.create_build_subset' do
77
+ subject { described_class.create_build_subset(test_files) }
78
+
10
79
  context "when test files doesn't exist" do
11
80
  let(:test_files) { [] }
12
81
 
@@ -0,0 +1,67 @@
1
+ describe KnapsackPro::Runners::Queue::BaseRunner do
2
+ describe '.run' do
3
+ it do
4
+ expect {
5
+ described_class.run(nil)
6
+ }.to raise_error NotImplementedError
7
+ end
8
+ end
9
+
10
+ describe '.run_tests' do
11
+ it do
12
+ expect {
13
+ described_class.run_tests(nil, nil, nil, nil)
14
+ }.to raise_error NotImplementedError
15
+ end
16
+ end
17
+
18
+ describe 'instance methods' do
19
+ let(:adapter_class) { double }
20
+ let(:runner) do
21
+ described_class.new(adapter_class)
22
+ end
23
+ let(:allocator) { instance_double(KnapsackPro::QueueAllocator) }
24
+ let(:allocator_builder) { instance_double(KnapsackPro::QueueAllocatorBuilder) }
25
+
26
+ before do
27
+ expect(KnapsackPro::QueueAllocatorBuilder).to receive(:new).with(adapter_class).and_return(allocator_builder)
28
+ expect(allocator_builder).to receive(:allocator).and_return(allocator)
29
+ end
30
+
31
+ describe '#test_file_paths' do
32
+ subject { runner.test_file_paths(args) }
33
+
34
+ context 'when can_initialize_queue flag has value' do
35
+ let(:can_initialize_queue) { double }
36
+ let(:args) { { can_initialize_queue: can_initialize_queue } }
37
+ let(:test_file_paths) { double }
38
+
39
+ before do
40
+ expect(allocator).to receive(:test_file_paths).and_return(test_file_paths)
41
+ end
42
+
43
+ it { should eq test_file_paths }
44
+ end
45
+
46
+ context 'when can_initialize_queue flag has no value' do
47
+ let(:args) { {} }
48
+
49
+ it do
50
+ expect { subject }.to raise_error(KeyError)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#test_dir' do
56
+ let(:test_dir) { double }
57
+
58
+ subject { runner.test_dir }
59
+
60
+ before do
61
+ expect(allocator_builder).to receive(:test_dir).and_return(test_dir)
62
+ end
63
+
64
+ it { should eq test_dir }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,118 @@
1
+ describe KnapsackPro::Runners::Queue::RSpecRunner do
2
+ describe '.run' do
3
+ let(:test_suite_token_rspec) { 'fake-token' }
4
+ let(:queue_id) { 'fake-queue-id' }
5
+ let(:runner) { double }
6
+
7
+ subject { described_class.run(args) }
8
+
9
+ before do
10
+ expect(KnapsackPro::Config::Env).to receive(:test_suite_token_rspec).and_return(test_suite_token_rspec)
11
+ expect(KnapsackPro::Config::EnvGenerator).to receive(:set_queue_id).and_return(queue_id)
12
+
13
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN', test_suite_token_rspec)
14
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_QUEUE_RECORDING_ENABLED', 'true')
15
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_QUEUE_ID', queue_id)
16
+
17
+ expect(described_class).to receive(:new).with(KnapsackPro::Adapters::RSpecAdapter).and_return(runner)
18
+ end
19
+
20
+ context 'when args provided' do
21
+ let(:args) { '--example-arg example-value' }
22
+
23
+ it do
24
+ result = double
25
+ expect(described_class).to receive(:run_tests).with(runner, true, ['--example-arg', 'example-value'], 0).and_return(result)
26
+
27
+ expect(subject).to eq result
28
+ end
29
+ end
30
+
31
+ context 'when args not provided' do
32
+ let(:args) { nil }
33
+
34
+ it do
35
+ result = double
36
+ expect(described_class).to receive(:run_tests).with(runner, true, [], 0).and_return(result)
37
+
38
+ expect(subject).to eq result
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '.run_tests' do
44
+ let(:test_dir) { 'fake-test-dir' }
45
+ let(:runner) do
46
+ instance_double(described_class, test_dir: test_dir)
47
+ end
48
+ let(:can_initialize_queue) { double(:can_initialize_queue) }
49
+ let(:args) { ['--example-arg', 'example-value'] }
50
+ let(:exitstatus) { double }
51
+
52
+ subject { described_class.run_tests(runner, can_initialize_queue, args, exitstatus) }
53
+
54
+ before do
55
+ expect(runner).to receive(:test_file_paths).with(can_initialize_queue: can_initialize_queue).and_return(test_file_paths)
56
+ end
57
+
58
+ context 'when test files exist' do
59
+ let(:test_file_paths) { ['a_spec.rb', 'b_spec.rb'] }
60
+
61
+ before do
62
+ subset_queue_id = 'fake-subset-queue-id'
63
+ expect(KnapsackPro::Config::EnvGenerator).to receive(:set_subset_queue_id).and_return(subset_queue_id)
64
+
65
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_SUBSET_QUEUE_ID', subset_queue_id)
66
+
67
+ options = double
68
+ expect(RSpec::Core::ConfigurationOptions).to receive(:new).with([
69
+ '--example-arg', 'example-value',
70
+ '--default-path', test_dir,
71
+ 'a_spec.rb', 'b_spec.rb',
72
+ ]).and_return(options)
73
+
74
+ rspec_core_runner = double
75
+ expect(RSpec::Core::Runner).to receive(:new).with(options).and_return(rspec_core_runner)
76
+ expect(rspec_core_runner).to receive(:run).with($stderr, $stdout).and_return(exit_code)
77
+
78
+ expect(RSpec).to receive_message_chain(:world, :example_groups, :clear)
79
+
80
+ # second call of run_tests because of recursion
81
+ expect(runner).to receive(:test_file_paths).with(can_initialize_queue: false).and_return([])
82
+ end
83
+
84
+ context 'when exit code is zero' do
85
+ let(:exit_code) { 0 }
86
+
87
+ it do
88
+ expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
89
+ expect(described_class).to receive(:exit).with(exitstatus)
90
+
91
+ subject
92
+ end
93
+ end
94
+
95
+ context 'when exit code is not zero' do
96
+ let(:exit_code) { double }
97
+
98
+ it do
99
+ expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
100
+ expect(described_class).to receive(:exit).with(exit_code)
101
+
102
+ subject
103
+ end
104
+ end
105
+ end
106
+
107
+ context "when test files don't exist" do
108
+ let(:test_file_paths) { [] }
109
+
110
+ it do
111
+ expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
112
+ expect(described_class).to receive(:exit).with(exitstatus)
113
+
114
+ subject
115
+ end
116
+ end
117
+ end
118
+ end
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.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-14 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -225,10 +225,12 @@ files:
225
225
  - lib/knapsack_pro/adapters/spinach_adapter.rb
226
226
  - lib/knapsack_pro/allocator.rb
227
227
  - lib/knapsack_pro/allocator_builder.rb
228
+ - lib/knapsack_pro/base_allocator_builder.rb
228
229
  - lib/knapsack_pro/client/api/action.rb
229
230
  - lib/knapsack_pro/client/api/v1/base.rb
230
231
  - lib/knapsack_pro/client/api/v1/build_distributions.rb
231
232
  - lib/knapsack_pro/client/api/v1/build_subsets.rb
233
+ - lib/knapsack_pro/client/api/v1/queues.rb
232
234
  - lib/knapsack_pro/client/connection.rb
233
235
  - lib/knapsack_pro/config/ci/base.rb
234
236
  - lib/knapsack_pro/config/ci/buildkite.rb
@@ -237,11 +239,14 @@ files:
237
239
  - lib/knapsack_pro/config/ci/snap_ci.rb
238
240
  - lib/knapsack_pro/config/ci/travis.rb
239
241
  - lib/knapsack_pro/config/env.rb
242
+ - lib/knapsack_pro/config/env_generator.rb
240
243
  - lib/knapsack_pro/crypto/decryptor.rb
241
244
  - lib/knapsack_pro/crypto/digestor.rb
242
245
  - lib/knapsack_pro/crypto/encryptor.rb
243
246
  - lib/knapsack_pro/logger_wrapper.rb
244
247
  - lib/knapsack_pro/presenter.rb
248
+ - lib/knapsack_pro/queue_allocator.rb
249
+ - lib/knapsack_pro/queue_allocator_builder.rb
245
250
  - lib/knapsack_pro/report.rb
246
251
  - lib/knapsack_pro/repository_adapter_initiator.rb
247
252
  - lib/knapsack_pro/repository_adapters/base_adapter.rb
@@ -250,6 +255,8 @@ files:
250
255
  - lib/knapsack_pro/runners/base_runner.rb
251
256
  - lib/knapsack_pro/runners/cucumber_runner.rb
252
257
  - lib/knapsack_pro/runners/minitest_runner.rb
258
+ - lib/knapsack_pro/runners/queue/base_runner.rb
259
+ - lib/knapsack_pro/runners/queue/rspec_runner.rb
253
260
  - lib/knapsack_pro/runners/rspec_runner.rb
254
261
  - lib/knapsack_pro/runners/spinach_runner.rb
255
262
  - lib/knapsack_pro/task_loader.rb
@@ -265,6 +272,7 @@ files:
265
272
  - lib/tasks/encrypted_test_file_names.rake
266
273
  - lib/tasks/install.rake
267
274
  - lib/tasks/minitest.rake
275
+ - lib/tasks/queue/rspec.rake
268
276
  - lib/tasks/rspec.rake
269
277
  - lib/tasks/salt.rake
270
278
  - lib/tasks/spinach.rake
@@ -281,10 +289,12 @@ files:
281
289
  - spec/knapsack_pro/adapters/spinach_adapter_spec.rb
282
290
  - spec/knapsack_pro/allocator_builder_spec.rb
283
291
  - spec/knapsack_pro/allocator_spec.rb
292
+ - spec/knapsack_pro/base_allocator_builder_spec.rb
284
293
  - spec/knapsack_pro/client/api/action_spec.rb
285
294
  - spec/knapsack_pro/client/api/v1/base_spec.rb
286
295
  - spec/knapsack_pro/client/api/v1/build_distributions_spec.rb
287
296
  - spec/knapsack_pro/client/api/v1/build_subsets_spec.rb
297
+ - spec/knapsack_pro/client/api/v1/queues_spec.rb
288
298
  - spec/knapsack_pro/client/connection_spec.rb
289
299
  - spec/knapsack_pro/config/ci/base_spec.rb
290
300
  - spec/knapsack_pro/config/ci/buildkite_spec.rb
@@ -292,12 +302,15 @@ files:
292
302
  - spec/knapsack_pro/config/ci/semaphore_spec.rb
293
303
  - spec/knapsack_pro/config/ci/snap_ci_spec.rb
294
304
  - spec/knapsack_pro/config/ci/travis_spec.rb
305
+ - spec/knapsack_pro/config/env_generator_spec.rb
295
306
  - spec/knapsack_pro/config/env_spec.rb
296
307
  - spec/knapsack_pro/crypto/decryptor_spec.rb
297
308
  - spec/knapsack_pro/crypto/digestor_spec.rb
298
309
  - spec/knapsack_pro/crypto/encryptor_spec.rb
299
310
  - spec/knapsack_pro/logger_wrapper_spec.rb
300
311
  - spec/knapsack_pro/presenter_spec.rb
312
+ - spec/knapsack_pro/queue_allocator_builder_spec.rb
313
+ - spec/knapsack_pro/queue_allocator_spec.rb
301
314
  - spec/knapsack_pro/report_spec.rb
302
315
  - spec/knapsack_pro/repository_adapter_initiator_spec.rb
303
316
  - spec/knapsack_pro/repository_adapters/base_adapter_spec.rb
@@ -306,6 +319,8 @@ files:
306
319
  - spec/knapsack_pro/runners/base_runner_spec.rb
307
320
  - spec/knapsack_pro/runners/cucumber_runner_spec.rb
308
321
  - spec/knapsack_pro/runners/minitest_runner_spec.rb
322
+ - spec/knapsack_pro/runners/queue/base_runner_spec.rb
323
+ - spec/knapsack_pro/runners/queue/rspec_runner_spec.rb
309
324
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
310
325
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
311
326
  - spec/knapsack_pro/task_loader_spec.rb
@@ -330,7 +345,7 @@ files:
330
345
  - test_fake/b_test.rb
331
346
  homepage: https://github.com/KnapsackPro/knapsack_pro-ruby
332
347
  licenses:
333
- - LGPLv3
348
+ - LGPL-3.0
334
349
  metadata: {}
335
350
  post_install_message:
336
351
  rdoc_options: []
@@ -348,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
363
  version: '0'
349
364
  requirements: []
350
365
  rubyforge_project:
351
- rubygems_version: 2.5.1
366
+ rubygems_version: 2.5.2
352
367
  signing_key:
353
368
  specification_version: 4
354
369
  summary: Knapsack Pro splits tests across CI nodes and makes sure that tests will
@@ -367,10 +382,12 @@ test_files:
367
382
  - spec/knapsack_pro/adapters/spinach_adapter_spec.rb
368
383
  - spec/knapsack_pro/allocator_builder_spec.rb
369
384
  - spec/knapsack_pro/allocator_spec.rb
385
+ - spec/knapsack_pro/base_allocator_builder_spec.rb
370
386
  - spec/knapsack_pro/client/api/action_spec.rb
371
387
  - spec/knapsack_pro/client/api/v1/base_spec.rb
372
388
  - spec/knapsack_pro/client/api/v1/build_distributions_spec.rb
373
389
  - spec/knapsack_pro/client/api/v1/build_subsets_spec.rb
390
+ - spec/knapsack_pro/client/api/v1/queues_spec.rb
374
391
  - spec/knapsack_pro/client/connection_spec.rb
375
392
  - spec/knapsack_pro/config/ci/base_spec.rb
376
393
  - spec/knapsack_pro/config/ci/buildkite_spec.rb
@@ -378,12 +395,15 @@ test_files:
378
395
  - spec/knapsack_pro/config/ci/semaphore_spec.rb
379
396
  - spec/knapsack_pro/config/ci/snap_ci_spec.rb
380
397
  - spec/knapsack_pro/config/ci/travis_spec.rb
398
+ - spec/knapsack_pro/config/env_generator_spec.rb
381
399
  - spec/knapsack_pro/config/env_spec.rb
382
400
  - spec/knapsack_pro/crypto/decryptor_spec.rb
383
401
  - spec/knapsack_pro/crypto/digestor_spec.rb
384
402
  - spec/knapsack_pro/crypto/encryptor_spec.rb
385
403
  - spec/knapsack_pro/logger_wrapper_spec.rb
386
404
  - spec/knapsack_pro/presenter_spec.rb
405
+ - spec/knapsack_pro/queue_allocator_builder_spec.rb
406
+ - spec/knapsack_pro/queue_allocator_spec.rb
387
407
  - spec/knapsack_pro/report_spec.rb
388
408
  - spec/knapsack_pro/repository_adapter_initiator_spec.rb
389
409
  - spec/knapsack_pro/repository_adapters/base_adapter_spec.rb
@@ -392,6 +412,8 @@ test_files:
392
412
  - spec/knapsack_pro/runners/base_runner_spec.rb
393
413
  - spec/knapsack_pro/runners/cucumber_runner_spec.rb
394
414
  - spec/knapsack_pro/runners/minitest_runner_spec.rb
415
+ - spec/knapsack_pro/runners/queue/base_runner_spec.rb
416
+ - spec/knapsack_pro/runners/queue/rspec_runner_spec.rb
395
417
  - spec/knapsack_pro/runners/rspec_runner_spec.rb
396
418
  - spec/knapsack_pro/runners/spinach_runner_spec.rb
397
419
  - spec/knapsack_pro/task_loader_spec.rb