knapsack_pro 2.2.0 → 2.6.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
  SHA256:
3
- metadata.gz: b399cf5cff114341276acbcc1c9c372ff4bfb51ffc05a5ee5b59cf531dc64feb
4
- data.tar.gz: aed0dea9791ab8589c63192e53b3f64c2a071f690553bc0d450be61d20b51b1e
3
+ metadata.gz: b4167b51e7f0af27a7d1482efb7a6c019f9aa99dd849f9488e47c4a33b5bd943
4
+ data.tar.gz: fff1d5e557813cd2829298c422d4ffae857e047d27aa001cf746a516270d9259
5
5
  SHA512:
6
- metadata.gz: d44d7d00c68d618d7ec41b764b28a8bcd7e5f2c62329d7246f2ee760f0d956ce7f1ffbbf6e8fae2adedf3cbd62d83a255f0b89a1dff9c8cc216d42cd11a89603
7
- data.tar.gz: 403cbc599ff70473aa07ae92abb73016a942c3ed21a2bbcb376ade1e8d0fe62e1ea64677fd6527c5a2b8822bd65fa7c6139ffb6c0850f273b795303974724bab
6
+ metadata.gz: fd9b442c01b5b58b295e6fc36d3879ddbf97b8770d4f96243f594f225ef3f73e23e75555cfba7adb6439dd5afa39a38ea756e5758628eed54c9305a12bd8b716
7
+ data.tar.gz: 7401c76f35ce8485a7dc8dc5742514803c8a045d7f431899b32aaa4795433b723b68e554386b7670abb367b1f9dfde2be9e4bc8b661ead354dbab366b56c1705
@@ -1,5 +1,47 @@
1
1
  # Change Log
2
2
 
3
+ ### 2.6.0
4
+
5
+ * Improve logger to show failed requests URL and when retry will happen
6
+
7
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/127
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.5.0...v2.6.0
10
+
11
+ ### 2.5.0
12
+
13
+ * Add production branch to non encryptable branches names
14
+
15
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/126
16
+
17
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.4.0...v2.5.0
18
+
19
+ ### 2.4.0
20
+
21
+ * Update list of non encryptable branches
22
+
23
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/125
24
+
25
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.3.0...v2.4.0
26
+
27
+ ### 2.3.0
28
+
29
+ * When you use Regular Mode then try 6 attempts to connect to the API instead of 3 attempts
30
+
31
+ Add `KNAPSACK_PRO_MAX_REQUEST_RETRIES` environment variable to let user define their own number of request retries to the API. It is useful to set it to `0` for [forked repos](https://knapsackpro.com/faq/question/how-to-make-knapsack_pro-works-for-forked-repositories-of-my-project) when you want to rely on Fallback Mode.
32
+
33
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/124
34
+
35
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.2.1...v2.3.0
36
+
37
+ ### 2.2.1
38
+
39
+ * Improve detection of test file path in test-unit runner for test files with shared examples
40
+
41
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/123
42
+
43
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.2.0...v2.2.1
44
+
3
45
  ### 2.2.0
4
46
 
5
47
  * Allow defining Queue Mode hooks multiple times (`KnapsackPro::Hooks::Queue.before_queue`, `KnapsackPro::Hooks::Queue.after_subset_queue`, `KnapsackPro::Hooks::Queue.after_queue`)
data/README.md CHANGED
@@ -2320,11 +2320,19 @@ There are a few ways to reproduce tests executed on CI node in your development
2320
2320
 
2321
2321
  ##### for knapsack_pro regular mode
2322
2322
 
2323
- knapsack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds til it switch to fallback behavior and it will split test files across CI nodes based on popular test directory names. When knapsack_pro starts fallback mode then you will see a warning in the output.
2323
+ knapsack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds till it switches to fallback behavior (Fallback Mode) and it will split test files across CI nodes based on popular test directory names. When knapsack_pro starts Fallback Mode then you will see a warning in the output.
2324
+
2325
+ Note there is an unlikely scenario when some of the CI nodes may start in Fallback Mode but others don't and then it could happen that some of test files might be skipped. You should [read this to learn more](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/124) and decide if you like to use Fallback Mode when running tests with knapsack_pro Regular Mode.
2326
+
2327
+ If your CI provider allows to retry only one of parallel CI nodes then please [read about this edge case as well](#required-ci-configuration-if-you-use-retry-single-failed-ci-node-feature-on-your-ci-server-when-knapsack_pro_fixed_queue_splittrue-in-queue-mode-or-knapsack_pro_fixed_test_suite_splittrue-in-regular-mode).
2324
2328
 
2325
2329
  ##### for knapsack_pro queue mode
2326
2330
 
2327
- knapsack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds till it switches to fallback behavior and it will split test files across CI nodes based on popular test directory names. Note that if one of CI nodes will lose connection to Knapsack Pro API but other not then you may see that some of the test files will be executed on multiple CI nodes. Fallback mode guarantees each of test files is run at least once across CI nodes. Thanks to that we know if the whole test suite is green or not. When knapsack_pro starts fallback mode then you will see a warning in the output.
2331
+ knapsack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds till it switches to fallback behavior (Fallback Mode) and it will split test files across CI nodes based on popular test directory names.
2332
+
2333
+ Note that if one of the CI nodes loses connection to Knapsack Pro API but others don't, then some of the test files may be executed on multiple CI nodes. **Fallback Mode guarantees each of the test files is run at least once across CI nodes when you use knapsack_pro in Queue Mode.** Thanks to that we know if the whole test suite is green or not. When knapsack_pro starts Fallback Mode then you will see a warning in the output.
2334
+
2335
+ If your CI provider allows to retry only one of parallel CI nodes then please [read about this edge case as well](#required-ci-configuration-if-you-use-retry-single-failed-ci-node-feature-on-your-ci-server-when-knapsack_pro_fixed_queue_splittrue-in-queue-mode-or-knapsack_pro_fixed_test_suite_splittrue-in-regular-mode).
2328
2336
 
2329
2337
  #### How can I change log level?
2330
2338
 
@@ -2464,12 +2472,13 @@ Below example is for rspec. You can change `$KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC
2464
2472
  if [ "$KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC" = "" ]; then
2465
2473
  KNAPSACK_PRO_ENDPOINT=https://api-disabled-for-fork.knapsackpro.com \
2466
2474
  KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=disabled-for-fork \
2475
+ KNAPSACK_PRO_MAX_REQUEST_RETRIES=0 \
2467
2476
  bundle exec rake knapsack_pro:rspec # use Regular Mode here always
2468
2477
  else
2469
2478
  # Regular Mode
2470
2479
  bundle exec rake knapsack_pro:rspec
2471
2480
 
2472
- # You can use Queue Mode instead of Regular Mode if you like
2481
+ # or you can use Queue Mode instead of Regular Mode if you like
2473
2482
  # bundle exec rake knapsack_pro:queue:rspec
2474
2483
  fi
2475
2484
  ```
@@ -3249,6 +3258,8 @@ $ gem build knapsack_pro.gemspec
3249
3258
  $ gem push knapsack_pro-X.X.X.gem
3250
3259
  ```
3251
3260
 
3261
+ Update the latest available gem version in `TestSuiteClientVersionChecker` for the Knapsack Pro API repository.
3262
+
3252
3263
  ## Mentions
3253
3264
 
3254
3265
  List of articles where people mentioned Knapsack Pro:
@@ -5,9 +5,29 @@ module KnapsackPro
5
5
  @@parent_of_test_dir = nil
6
6
 
7
7
  def self.test_path(obj)
8
- first_test = obj.tests.first
9
- method = first_test.method_name
10
- full_test_path = first_test.method(method).source_location.first
8
+ full_test_path = nil
9
+ found_valid_test_file_path = false
10
+
11
+ obj.tests.each do |test_obj|
12
+ method = test_obj.method_name
13
+ full_test_path = test_obj.method(method).source_location.first
14
+ # if we find a test file path that is a valid test file path within test suite directory
15
+ # then break to stop looking further.
16
+ # If we won't find a valid test file path then the last found path will be used as full_test_path
17
+ # For instance if test file contains only shared examples then it's not possible to properly detect test file path
18
+ # so the wrong path can be used like:
19
+ # /Users/artur/.rvm/gems/ruby-2.6.5/gems/shared_should-0.10.0/lib/shared_should/shared_context.rb
20
+ if full_test_path.include?(@@parent_of_test_dir)
21
+ found_valid_test_file_path = true
22
+ break
23
+ end
24
+ end
25
+
26
+ unless found_valid_test_file_path
27
+ KnapsackPro.logger.warn('cannot detect a valid test file path. Probably the test file contains only shared examples. Please add test cases to your test file. Read more at https://github.com/KnapsackPro/knapsack_pro-ruby/pull/123')
28
+ KnapsackPro.logger.warn("See test file for #{obj.inspect}")
29
+ end
30
+
11
31
  parent_of_test_dir_regexp = Regexp.new("^#{@@parent_of_test_dir}")
12
32
  test_path = full_test_path.gsub(parent_of_test_dir_regexp, '.')
13
33
  # test_path will look like ./test/dir/unit_test.rb
@@ -4,7 +4,6 @@ module KnapsackPro
4
4
  class ServerError < StandardError; end
5
5
 
6
6
  TIMEOUT = 15
7
- MAX_RETRY = -> { KnapsackPro::Config::Env.fallback_mode_enabled? ? 3 : 6 }
8
7
  REQUEST_RETRY_TIMEBOX = 8
9
8
 
10
9
  def initialize(action)
@@ -116,14 +115,19 @@ module KnapsackPro
116
115
 
117
116
  response_body
118
117
  rescue ServerError, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE, EOFError, SocketError, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError => e
118
+ logger.warn("#{action.http_method.to_s.upcase} #{endpoint_url}")
119
+ logger.warn('Request failed due to:')
119
120
  logger.warn(e.inspect)
120
121
  retries += 1
121
- if retries < MAX_RETRY.call
122
+ if retries < max_request_retries
122
123
  wait = retries * REQUEST_RETRY_TIMEBOX
123
- logger.warn("Wait #{wait}s and retry request to Knapsack Pro API.")
124
124
  print_every = 2 # seconds
125
125
  (wait / print_every).ceil.times do |i|
126
- logger.warn("Next request in #{wait - i * print_every}s...")
126
+ if i == 0
127
+ logger.warn("Wait for #{wait}s before retrying the request to Knapsack Pro API.")
128
+ else
129
+ logger.warn("#{wait - i * print_every}s left before retry...")
130
+ end
127
131
  Kernel.sleep(print_every)
128
132
  end
129
133
  retry
@@ -156,6 +160,22 @@ module KnapsackPro
156
160
  http.get(uri, json_headers)
157
161
  end
158
162
  end
163
+
164
+ def max_request_retries
165
+ # when user defined max request retries
166
+ return KnapsackPro::Config::Env.max_request_retries if KnapsackPro::Config::Env.max_request_retries
167
+
168
+ # when Fallback Mode is disabled then try more attempts to connect to the API
169
+ return 6 unless KnapsackPro::Config::Env.fallback_mode_enabled?
170
+
171
+ # when Regular Mode then try more attempts to connect to the API
172
+ # if only one CI node starts Fallback Mode instead of all then we can't guarantee all test files will be run
173
+ # https://github.com/KnapsackPro/knapsack_pro-ruby/pull/124
174
+ return 6 if KnapsackPro::Config::Env.regular_mode?
175
+
176
+ # default number of attempts
177
+ 3
178
+ end
159
179
  end
160
180
  end
161
181
  end
@@ -36,6 +36,13 @@ module KnapsackPro
36
36
  ).to_i
37
37
  end
38
38
 
39
+ def max_request_retries
40
+ number = ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES']
41
+ if number
42
+ number.to_i
43
+ end
44
+ end
45
+
39
46
  def commit_hash
40
47
  ENV['KNAPSACK_PRO_COMMIT_HASH'] ||
41
48
  ci_env_for(:commit_hash)
@@ -83,6 +90,10 @@ module KnapsackPro
83
90
  recording_enabled == 'true'
84
91
  end
85
92
 
93
+ def regular_mode?
94
+ recording_enabled?
95
+ end
96
+
86
97
  def queue_recording_enabled
87
98
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED']
88
99
  end
@@ -1,7 +1,23 @@
1
1
  module KnapsackPro
2
2
  module Crypto
3
3
  class BranchEncryptor
4
- NON_ENCRYPTABLE_BRANCHES = %w(develop development dev master staging)
4
+ NON_ENCRYPTABLE_BRANCHES = [
5
+ 'master',
6
+ 'main',
7
+ 'develop',
8
+ 'development',
9
+ 'dev',
10
+ 'staging',
11
+ 'production',
12
+ # GitHub Actions has branch names starting with refs/heads/
13
+ 'refs/heads/master',
14
+ 'refs/heads/main',
15
+ 'refs/heads/develop',
16
+ 'refs/heads/development',
17
+ 'refs/heads/dev',
18
+ 'refs/heads/staging',
19
+ 'refs/heads/production',
20
+ ]
5
21
 
6
22
  def self.call(branch)
7
23
  if KnapsackPro::Config::Env.branch_encrypted?
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '2.2.0'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -10,8 +10,7 @@ describe KnapsackPro::Adapters::TestUnitAdapter do
10
10
 
11
11
  before do
12
12
  parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
13
- parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
14
- described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
13
+ described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir)
15
14
  end
16
15
 
17
16
  context 'when regular test' do
@@ -84,22 +84,22 @@ shared_examples 'when retry request' do
84
84
  expect(logger).to receive(:error).exactly(3).with(parsed_response)
85
85
 
86
86
  server_error = described_class::ServerError.new(parsed_response)
87
+ expect(logger).to receive(:warn).exactly(3).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
88
+ expect(logger).to receive(:warn).exactly(3).with('Request failed due to:')
87
89
  expect(logger).to receive(:warn).exactly(3).with(server_error.inspect)
88
90
 
89
- expect(logger).to receive(:warn).with("Wait 8s and retry request to Knapsack Pro API.")
90
- expect(logger).to receive(:warn).with("Next request in 8s...")
91
- expect(logger).to receive(:warn).with("Next request in 6s...")
92
- expect(logger).to receive(:warn).with("Next request in 4s...")
93
- expect(logger).to receive(:warn).with("Next request in 2s...")
94
- expect(logger).to receive(:warn).with("Wait 16s and retry request to Knapsack Pro API.")
95
- expect(logger).to receive(:warn).with("Next request in 16s...")
96
- expect(logger).to receive(:warn).with("Next request in 14s...")
97
- expect(logger).to receive(:warn).with("Next request in 12s...")
98
- expect(logger).to receive(:warn).with("Next request in 10s...")
99
- expect(logger).to receive(:warn).with("Next request in 8s...")
100
- expect(logger).to receive(:warn).with("Next request in 6s...")
101
- expect(logger).to receive(:warn).with("Next request in 4s...")
102
- expect(logger).to receive(:warn).with("Next request in 2s...")
91
+ expect(logger).to receive(:warn).with("Wait for 8s before retrying the request to Knapsack Pro API.")
92
+ expect(logger).to receive(:warn).with("6s left before retry...")
93
+ expect(logger).to receive(:warn).with("4s left before retry...")
94
+ expect(logger).to receive(:warn).with("2s left before retry...")
95
+ expect(logger).to receive(:warn).with("Wait for 16s before retrying the request to Knapsack Pro API.")
96
+ expect(logger).to receive(:warn).with("14s left before retry...")
97
+ expect(logger).to receive(:warn).with("12s left before retry...")
98
+ expect(logger).to receive(:warn).with("10s left before retry...")
99
+ expect(logger).to receive(:warn).with("8s left before retry...")
100
+ expect(logger).to receive(:warn).with("6s left before retry...")
101
+ expect(logger).to receive(:warn).with("4s left before retry...")
102
+ expect(logger).to receive(:warn).with("2s left before retry...")
103
103
  expect(Kernel).to receive(:sleep).exactly(12).with(2)
104
104
 
105
105
  expect(subject).to eq(parsed_response)
@@ -108,6 +108,53 @@ shared_examples 'when retry request' do
108
108
  expect(connection.errors?).to be true
109
109
  end
110
110
 
111
+ context 'when max request retries defined' do
112
+ before do
113
+ expect(KnapsackPro::Config::Env).to receive(:max_request_retries).at_least(1).and_return(4)
114
+ end
115
+
116
+ it do
117
+ expect(logger).to receive(:debug).exactly(4).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
118
+ expect(logger).to receive(:debug).exactly(4).with('API request UUID: fake-uuid')
119
+ expect(logger).to receive(:debug).exactly(4).with('API response:')
120
+
121
+ parsed_response = { 'error' => 'Internal Server Error' }
122
+
123
+ expect(logger).to receive(:error).exactly(4).with(parsed_response)
124
+
125
+ server_error = described_class::ServerError.new(parsed_response)
126
+ expect(logger).to receive(:warn).exactly(4).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
127
+ expect(logger).to receive(:warn).exactly(4).with('Request failed due to:')
128
+ expect(logger).to receive(:warn).exactly(4).with(server_error.inspect)
129
+
130
+ expect(logger).to receive(:warn).with("Wait for 8s before retrying the request to Knapsack Pro API.")
131
+ expect(logger).to receive(:warn).with("6s left before retry...")
132
+ expect(logger).to receive(:warn).with("4s left before retry...")
133
+ expect(logger).to receive(:warn).with("2s left before retry...")
134
+
135
+ expect(logger).to receive(:warn).with("Wait for 16s before retrying the request to Knapsack Pro API.")
136
+ expect(logger).to receive(:warn).with("14s left before retry...")
137
+ expect(logger).to receive(:warn).with("12s left before retry...")
138
+ expect(logger).to receive(:warn).with("10s left before retry...")
139
+ expect(logger).to receive(:warn).with("8s left before retry...")
140
+ expect(logger).to receive(:warn).with("6s left before retry...")
141
+ expect(logger).to receive(:warn).with("4s left before retry...")
142
+ expect(logger).to receive(:warn).with("2s left before retry...")
143
+
144
+ expect(logger).to receive(:warn).with("Wait for 24s before retrying the request to Knapsack Pro API.")
145
+ 11.times do |i|
146
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
147
+ end
148
+
149
+ expect(Kernel).to receive(:sleep).exactly(4+8+12).with(2)
150
+
151
+ expect(subject).to eq(parsed_response)
152
+
153
+ expect(connection.success?).to be false
154
+ expect(connection.errors?).to be true
155
+ end
156
+ end
157
+
111
158
  context 'when Fallback Mode is disabled' do
112
159
  before do
113
160
  expect(KnapsackPro::Config::Env).to receive(:fallback_mode_enabled?).at_least(1).and_return(false)
@@ -123,37 +170,94 @@ shared_examples 'when retry request' do
123
170
  expect(logger).to receive(:error).exactly(6).with(parsed_response)
124
171
 
125
172
  server_error = described_class::ServerError.new(parsed_response)
173
+ expect(logger).to receive(:warn).exactly(6).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
174
+ expect(logger).to receive(:warn).exactly(6).with('Request failed due to:')
175
+ expect(logger).to receive(:warn).exactly(6).with(server_error.inspect)
176
+
177
+ expect(logger).to receive(:warn).with("Wait for 8s before retrying the request to Knapsack Pro API.")
178
+ expect(logger).to receive(:warn).with("6s left before retry...")
179
+ expect(logger).to receive(:warn).with("4s left before retry...")
180
+ expect(logger).to receive(:warn).with("2s left before retry...")
181
+
182
+ expect(logger).to receive(:warn).with("Wait for 16s before retrying the request to Knapsack Pro API.")
183
+ expect(logger).to receive(:warn).with("14s left before retry...")
184
+ expect(logger).to receive(:warn).with("12s left before retry...")
185
+ expect(logger).to receive(:warn).with("10s left before retry...")
186
+ expect(logger).to receive(:warn).with("8s left before retry...")
187
+ expect(logger).to receive(:warn).with("6s left before retry...")
188
+ expect(logger).to receive(:warn).with("4s left before retry...")
189
+ expect(logger).to receive(:warn).with("2s left before retry...")
190
+
191
+ expect(logger).to receive(:warn).with("Wait for 24s before retrying the request to Knapsack Pro API.")
192
+ 11.times do |i|
193
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
194
+ end
195
+
196
+ expect(logger).to receive(:warn).with("Wait for 32s before retrying the request to Knapsack Pro API.")
197
+ 15.times do |i|
198
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
199
+ end
200
+
201
+ expect(logger).to receive(:warn).with("Wait for 40s before retrying the request to Knapsack Pro API.")
202
+ 19.times do |i|
203
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
204
+ end
205
+
206
+ expect(Kernel).to receive(:sleep).exactly(60).with(2)
207
+
208
+ expect(subject).to eq(parsed_response)
209
+
210
+ expect(connection.success?).to be false
211
+ expect(connection.errors?).to be true
212
+ end
213
+ end
214
+
215
+ context 'when Regular Mode' do
216
+ before do
217
+ expect(KnapsackPro::Config::Env).to receive(:regular_mode?).at_least(1).and_return(true)
218
+ end
219
+
220
+ it do
221
+ expect(logger).to receive(:debug).exactly(6).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
222
+ expect(logger).to receive(:debug).exactly(6).with('API request UUID: fake-uuid')
223
+ expect(logger).to receive(:debug).exactly(6).with('API response:')
224
+
225
+ parsed_response = { 'error' => 'Internal Server Error' }
226
+
227
+ expect(logger).to receive(:error).exactly(6).with(parsed_response)
228
+
229
+ server_error = described_class::ServerError.new(parsed_response)
230
+ expect(logger).to receive(:warn).exactly(6).with("#{expected_http_method} http://api.knapsackpro.test:3000/v1/fake_endpoint")
231
+ expect(logger).to receive(:warn).exactly(6).with('Request failed due to:')
126
232
  expect(logger).to receive(:warn).exactly(6).with(server_error.inspect)
127
233
 
128
- expect(logger).to receive(:warn).with("Wait 8s and retry request to Knapsack Pro API.")
129
- expect(logger).to receive(:warn).with("Next request in 8s...")
130
- expect(logger).to receive(:warn).with("Next request in 6s...")
131
- expect(logger).to receive(:warn).with("Next request in 4s...")
132
- expect(logger).to receive(:warn).with("Next request in 2s...")
133
-
134
- expect(logger).to receive(:warn).with("Wait 16s and retry request to Knapsack Pro API.")
135
- expect(logger).to receive(:warn).with("Next request in 16s...")
136
- expect(logger).to receive(:warn).with("Next request in 14s...")
137
- expect(logger).to receive(:warn).with("Next request in 12s...")
138
- expect(logger).to receive(:warn).with("Next request in 10s...")
139
- expect(logger).to receive(:warn).with("Next request in 8s...")
140
- expect(logger).to receive(:warn).with("Next request in 6s...")
141
- expect(logger).to receive(:warn).with("Next request in 4s...")
142
- expect(logger).to receive(:warn).with("Next request in 2s...")
143
-
144
- expect(logger).to receive(:warn).with("Wait 24s and retry request to Knapsack Pro API.")
145
- 12.times do |i|
146
- expect(logger).to receive(:warn).with("Next request in #{(i+1)*2}s...")
234
+ expect(logger).to receive(:warn).with("Wait for 8s before retrying the request to Knapsack Pro API.")
235
+ expect(logger).to receive(:warn).with("6s left before retry...")
236
+ expect(logger).to receive(:warn).with("4s left before retry...")
237
+ expect(logger).to receive(:warn).with("2s left before retry...")
238
+
239
+ expect(logger).to receive(:warn).with("Wait for 16s before retrying the request to Knapsack Pro API.")
240
+ expect(logger).to receive(:warn).with("14s left before retry...")
241
+ expect(logger).to receive(:warn).with("12s left before retry...")
242
+ expect(logger).to receive(:warn).with("10s left before retry...")
243
+ expect(logger).to receive(:warn).with("8s left before retry...")
244
+ expect(logger).to receive(:warn).with("6s left before retry...")
245
+ expect(logger).to receive(:warn).with("4s left before retry...")
246
+ expect(logger).to receive(:warn).with("2s left before retry...")
247
+
248
+ expect(logger).to receive(:warn).with("Wait for 24s before retrying the request to Knapsack Pro API.")
249
+ 11.times do |i|
250
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
147
251
  end
148
252
 
149
- expect(logger).to receive(:warn).with("Wait 32s and retry request to Knapsack Pro API.")
150
- 16.times do |i|
151
- expect(logger).to receive(:warn).with("Next request in #{(i+1)*2}s...")
253
+ expect(logger).to receive(:warn).with("Wait for 32s before retrying the request to Knapsack Pro API.")
254
+ 15.times do |i|
255
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
152
256
  end
153
257
 
154
- expect(logger).to receive(:warn).with("Wait 40s and retry request to Knapsack Pro API.")
155
- 20.times do |i|
156
- expect(logger).to receive(:warn).with("Next request in #{(i+1)*2}s...")
258
+ expect(logger).to receive(:warn).with("Wait for 40s before retrying the request to Knapsack Pro API.")
259
+ 19.times do |i|
260
+ expect(logger).to receive(:warn).with("#{(i+1)*2}s left before retry...")
157
261
  end
158
262
 
159
263
  expect(Kernel).to receive(:sleep).exactly(60).with(2)
@@ -100,6 +100,19 @@ describe KnapsackPro::Config::Env do
100
100
  end
101
101
  end
102
102
 
103
+ describe '.max_request_retries' do
104
+ subject { described_class.max_request_retries }
105
+
106
+ context 'when ENV exists' do
107
+ before { stub_const("ENV", { 'KNAPSACK_PRO_MAX_REQUEST_RETRIES' => '2' }) }
108
+ it { should eq 2 }
109
+ end
110
+
111
+ context "when ENV doesn't exist" do
112
+ it { should be_nil }
113
+ end
114
+ end
115
+
103
116
  describe '.commit_hash' do
104
117
  subject { described_class.commit_hash }
105
118
 
@@ -267,6 +280,25 @@ describe KnapsackPro::Config::Env do
267
280
  end
268
281
  end
269
282
 
283
+
284
+ describe '.regular_mode?' do
285
+ subject { described_class.regular_mode? }
286
+
287
+ before do
288
+ expect(described_class).to receive(:recording_enabled?).and_return(recording_enabled)
289
+ end
290
+
291
+ context 'when recording is enabled' do
292
+ let(:recording_enabled) { true }
293
+ it { should be true }
294
+ end
295
+
296
+ context 'when recording is not enabled' do
297
+ let(:recording_enabled) { false }
298
+ it { should be false }
299
+ end
300
+ end
301
+
270
302
  describe '.recording_enabled?' do
271
303
  subject { described_class.recording_enabled? }
272
304
 
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: 2.2.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake