knapsack_pro 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a2674eb030549459a86c2b78ad2242a08b708e7
4
- data.tar.gz: abc36e6d8db2242652694a2394dc724f878caf2d
3
+ metadata.gz: 7b9017e6211e870280789b77926d157894d6ea0a
4
+ data.tar.gz: 72749308b9dcc9737efb3a210853c7c69d17669d
5
5
  SHA512:
6
- metadata.gz: 32bcf9bf8cf8fbad5f254bd9488b11d2f09cf569f0cc63165afeba51bd1cb85e728e780183ca7844ce8a922f89e12d1c76cb5f48b2763ecef6c77807082f259d
7
- data.tar.gz: f1ca9ce31b3f29fedfd175296d3c306588200ca9d7ea9f87e322c7f423c1b041a1cf662b82fcef581a9fe0203bff22ab8325a23484cf22e57ce7d8c98fab59b5
6
+ metadata.gz: 5a83dd2ef1307dd014a8ec3151e959e2806551a11f238a4f7d06bb80c3b6422a33b88b0f13b1c8e92c4ec86a5b8605a74b5f76c83ad644d7d5eb8f58954c5171
7
+ data.tar.gz: 2fa61c851548c36e23dd31888d1bffcaa2226eaf56893e92bba7bec4d4547b6a6f47477a219fde05f698b28b524d618f96a7836428b3ce30327dc1681a422f82
data/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 0.10.0
6
+
7
+ * Add new environment variable `KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT`. The default value is true.
8
+
9
+ It means when you run test suite again for the same commit hash and total number of nodes and for the same branch
10
+ then you will get exactly the same test suite split.
11
+ This is the new default behavior for the knapsack_pro gem. Thanks to that when tests on one of your node failed
12
+ you can retry the node with exactly the same subset of tests that were run on the node in the first place.
13
+
14
+ There is one edge case. When you run tests for the first time and there is no data collected about time execution of your tests then
15
+ we need to collect data to prepare the first test suite split. The second run of your tests will have fixed test suite split.
16
+ To compare if all your CI nodes are running based on the same test suite split seed you can check the value for seed in knapsack logging message
17
+ before your test starts. The message looks like:
18
+
19
+ [knapsack_pro] Test suite split seed: 8a606431-02a1-4766-9878-0ea42a07ad21
20
+
21
+ * Show test suite split seed in logger based on `build_distribution_id` from Knapsack Pro API.
22
+ * Send `fixed_test_suite_split` param to build distribution Knapsack Pro API endpoint.
23
+
24
+ Related issues:
25
+
26
+ * https://github.com/KnapsackPro/knapsack_pro-ruby/issues/15
27
+ * https://github.com/KnapsackPro/knapsack_pro-ruby/issues/12
28
+
29
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.9.0...v0.10.0
30
+
5
31
  ### 0.9.0
6
32
 
7
33
  * Add https support for Knapsack Pro API endpoint
data/README.md CHANGED
@@ -68,6 +68,7 @@ For instance when you will run tests with rake knapsack_pro:rspec then:
68
68
  - [When you set global variable `KNAPSACK_PRO_REPOSITORY_ADAPTER=git` (required when CI provider is not supported)](#when-you-set-global-variable-knapsack_pro_repository_adaptergit-required-when-ci-provider-is-not-supported)
69
69
  - [Extra configuration for CI server](#extra-configuration-for-ci-server)
70
70
  - [Info about ENV variables](#info-about-env-variables)
71
+ - [KNAPSACK_PRO_FIXED_TEST_SUITE_SPLITE (test suite split based on seed)](#knapsack_pro_fixed_test_suite_splite-test-suite-split-based-on-seed)
71
72
  - [Environment variables for debugging gem](#environment-variables-for-debugging-gem)
72
73
  - [Passing arguments to rake task](#passing-arguments-to-rake-task)
73
74
  - [Passing arguments to rspec](#passing-arguments-to-rspec)
@@ -268,6 +269,38 @@ In case when you use other CI provider for instance [Jenkins](https://jenkins-ci
268
269
 
269
270
  `KNAPSACK_PRO_CI_NODE_INDEX` - index of current CI node starts from 0. Second CI node should have `KNAPSACK_PRO_CI_NODE_INDEX=1`.
270
271
 
272
+ #### KNAPSACK_PRO_FIXED_TEST_SUITE_SPLITE (test suite split based on seed)
273
+
274
+ * `KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true` (default)
275
+
276
+ It means when you run test suite again for the same commit hash and total number of nodes and for the same branch
277
+ then you will get exactly the same test suite split.
278
+
279
+ Thanks to that when tests on one of your node failed you can retry the node with exactly the same subset of tests that were run on the node in the first place.
280
+
281
+ There is one edge case. When you run tests for the first time and there is no data collected about time execution of your tests then
282
+ we need to collect data to prepare the first test suite split. The second run of your tests will have fixed test suite split.
283
+
284
+ To compare if all your CI nodes are running based on the same test suite split seed you can check the value for seed in knapsack logging message
285
+ before your test starts. The message looks like:
286
+
287
+ [knapsack_pro] Test suite split seed: 8a606431-02a1-4766-9878-0ea42a07ad21
288
+
289
+ * `KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false`
290
+
291
+ When you disable fixed test suite split then your will get test suite split based on most up to date data about your test suite time execution.
292
+ For instance, when you run tests for the second time for the same commit hash then your will get more optimal test suite split than it was on the first run.
293
+
294
+ Don't disable fixed test suite split when:
295
+
296
+ * you expect to run the same subset of test suite multiple times for the same node (for instance your would like to retry only single CI node that failed)
297
+
298
+ Example of issue: https://github.com/KnapsackPro/knapsack_pro-ruby/issues/15
299
+
300
+ * you start your tests not at the same time across your CI nodes. For instance, one of the CI node finished faster than the other CI node started. This would change the seed for the second CI node that started later.
301
+
302
+ Example of issue: https://github.com/KnapsackPro/knapsack_pro-ruby/issues/12
303
+
271
304
  #### Environment variables for debugging gem
272
305
 
273
306
  `KNAPSACK_PRO_ENDPOINT` - Default value is `http://api.knapsackpro.com` which is endpoint for [Knapsack Pro API](http://docs.knapsackpro.com).
@@ -9,6 +9,7 @@ module KnapsackPro
9
9
  endpoint_path: '/v1/build_distributions/subset',
10
10
  http_method: :post,
11
11
  request_hash: {
12
+ :fixed_test_suite_split => KnapsackPro::Config::Env.fixed_test_suite_split,
12
13
  :commit_hash => args.fetch(:commit_hash),
13
14
  :branch => args.fetch(:branch),
14
15
  :node_total => args.fetch(:node_total),
@@ -65,6 +65,15 @@ module KnapsackPro
65
65
  nil
66
66
  end
67
67
 
68
+ def seed
69
+ return if @response.nil? || @response == ''
70
+ response['build_distribution_id']
71
+ end
72
+
73
+ def has_seed?
74
+ !seed.nil?
75
+ end
76
+
68
77
  def post
69
78
  uri = URI.parse(endpoint_url)
70
79
  http = Net::HTTP.new(uri.host, uri.port)
@@ -78,6 +87,7 @@ module KnapsackPro
78
87
  request_uuid = http_response.header['X-Request-Id']
79
88
 
80
89
  logger.info("API request UUID: #{request_uuid}")
90
+ logger.info("Test suite split seed: #{seed}") if has_seed?
81
91
  logger.info('API response:')
82
92
  if errors?
83
93
  logger.error(response)
@@ -61,6 +61,10 @@ module KnapsackPro
61
61
  end
62
62
  end
63
63
 
64
+ def fixed_test_suite_split
65
+ ENV.fetch('KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT', true)
66
+ end
67
+
64
68
  def test_suite_token
65
69
  required_env('KNAPSACK_PRO_TEST_SUITE_TOKEN')
66
70
  end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -29,24 +29,24 @@ http_interactions:
29
29
  Content-Type:
30
30
  - application/json; charset=utf-8
31
31
  Etag:
32
- - W/"2348448eb68a360747d21fe1bb304d5b"
32
+ - W/"bba747f5e635a765e120718b7876d174"
33
33
  Cache-Control:
34
34
  - max-age=0, private, must-revalidate
35
35
  X-Request-Id:
36
- - 66e07e14-0dfd-43f9-b331-2a930141dfef
36
+ - 190e26fb-676b-4b85-9737-8a90d0cce310
37
37
  X-Runtime:
38
- - '0.158064'
38
+ - '0.639590'
39
39
  Server:
40
40
  - WEBrick/1.3.1 (Ruby/2.2.3/2015-08-18)
41
41
  Date:
42
- - Fri, 23 Oct 2015 20:12:23 GMT
42
+ - Tue, 28 Jun 2016 20:40:35 GMT
43
43
  Content-Length:
44
- - '74'
44
+ - '137'
45
45
  Connection:
46
46
  - Keep-Alive
47
47
  body:
48
48
  encoding: UTF-8
49
- string: '{"node_index":1,"test_files":[{"path":"b_spec.rb","time_execution":null}]}'
49
+ string: '{"build_distribution_id":"1f905f45-c203-40f1-9891-d9a91dd11245","node_index":1,"test_files":[{"path":"b_spec.rb","time_execution":null}]}'
50
50
  http_version:
51
- recorded_at: Fri, 23 Oct 2015 20:12:23 GMT
51
+ recorded_at: Tue, 28 Jun 2016 20:40:35 GMT
52
52
  recorded_with: VCR 2.9.3
@@ -1,5 +1,6 @@
1
1
  describe KnapsackPro::Client::API::V1::BuildDistributions do
2
2
  describe '.subset' do
3
+ let(:fixed_test_suite_split) { double }
3
4
  let(:commit_hash) { double }
4
5
  let(:branch) { double }
5
6
  let(:node_total) { double }
@@ -16,12 +17,17 @@ describe KnapsackPro::Client::API::V1::BuildDistributions do
16
17
  )
17
18
  end
18
19
 
20
+ before do
21
+ expect(KnapsackPro::Config::Env).to receive(:fixed_test_suite_split).and_return(fixed_test_suite_split)
22
+ end
23
+
19
24
  it do
20
25
  action = double
21
26
  expect(KnapsackPro::Client::API::Action).to receive(:new).with({
22
27
  endpoint_path: '/v1/build_distributions/subset',
23
28
  http_method: :post,
24
29
  request_hash: {
30
+ fixed_test_suite_split: fixed_test_suite_split,
25
31
  commit_hash: commit_hash,
26
32
  branch: branch,
27
33
  node_total: node_total,
@@ -40,15 +40,17 @@ describe KnapsackPro::Client::Connection do
40
40
  "{\"fake\":\"hash\",\"test_suite_token\":\"3fa64859337f6e56409d49f865d13fd7\"}",
41
41
  { "Content-Type" => "application/json", "Accept" => "application/json" }
42
42
  ).and_return(http_response)
43
-
44
- expect(KnapsackPro).to receive(:logger).exactly(3).and_return(logger)
45
- expect(logger).to receive(:info).with('API request UUID: fake-uuid')
46
- expect(logger).to receive(:info).with('API response:')
47
43
  end
48
44
 
49
45
  context 'when body response is json' do
50
46
  let(:body) { '{"errors": "value"}' }
51
47
 
48
+ before do
49
+ expect(KnapsackPro).to receive(:logger).exactly(3).and_return(logger)
50
+ expect(logger).to receive(:info).with('API request UUID: fake-uuid')
51
+ expect(logger).to receive(:info).with('API response:')
52
+ end
53
+
52
54
  it do
53
55
  parsed_response = { 'errors' => 'value' }
54
56
 
@@ -60,9 +62,36 @@ describe KnapsackPro::Client::Connection do
60
62
  end
61
63
  end
62
64
 
65
+ context 'when body response is json with build_distribution_id' do
66
+ let(:body) { '{"build_distribution_id": "seed-uuid"}' }
67
+
68
+ before do
69
+ expect(KnapsackPro).to receive(:logger).exactly(4).and_return(logger)
70
+ expect(logger).to receive(:info).with('API request UUID: fake-uuid')
71
+ expect(logger).to receive(:info).with("Test suite split seed: seed-uuid")
72
+ expect(logger).to receive(:info).with('API response:')
73
+ end
74
+
75
+ it do
76
+ parsed_response = { 'build_distribution_id' => 'seed-uuid' }
77
+
78
+ expect(logger).to receive(:info).with(parsed_response)
79
+
80
+ expect(subject).to eq(parsed_response)
81
+ expect(connection.success?).to be true
82
+ expect(connection.errors?).to be false
83
+ end
84
+ end
85
+
63
86
  context 'when body response is empty' do
64
87
  let(:body) { '' }
65
88
 
89
+ before do
90
+ expect(KnapsackPro).to receive(:logger).exactly(3).and_return(logger)
91
+ expect(logger).to receive(:info).with('API request UUID: fake-uuid')
92
+ expect(logger).to receive(:info).with('API response:')
93
+ end
94
+
66
95
  it do
67
96
  expect(logger).to receive(:info).with('')
68
97
 
@@ -219,6 +219,20 @@ describe KnapsackPro::Config::Env do
219
219
  end
220
220
  end
221
221
 
222
+ describe '.fixed_test_suite_split' do
223
+ subject { described_class.fixed_test_suite_split }
224
+
225
+ context 'when ENV exists' do
226
+ before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT' => false }) }
227
+ it { should eq false }
228
+ end
229
+
230
+ context "when ENV doesn't exist" do
231
+ before { stub_const("ENV", {}) }
232
+ it { should be true }
233
+ end
234
+ end
235
+
222
236
  describe '.test_suite_token' do
223
237
  subject { described_class.test_suite_token }
224
238
 
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.9.0
4
+ version: 0.10.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-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake