Skip to content

Commit ba78601

Browse files
committed
Fix errors
1 parent 47e52bc commit ba78601

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/optimizely/cmab/cmab_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _do_fetch_with_retry(url, request_body, retry_config, timeout)
158158
rescue => e
159159
last_error = e
160160
if attempt < retry_config.max_retries
161-
@logger.log(Logger::INFO, "Retrying CMAB request (attempt #{attempt + 1} after #{backoff} seconds)...")
161+
@logger.log(Logger::INFO, "Retrying CMAB request (attempt #{attempt + 1}) after #{backoff} seconds...")
162162
sleep(backoff)
163163
backoff = [backoff * (retry_config.backoff_multiplier**(attempt + 1)), retry_config.max_backoff].min
164164
end

spec/cmab_client_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
# Mock successful response
134134
mock_response = double('response', status_code: 200, json: {'predictions' => [{'variationId' => 'abc123'}]})
135135
allow(mock_http_client).to receive(:post).and_return(mock_response)
136-
allow_any_instance_of(Object).to receive(:sleep)
136+
allow(Kernel).to receive(:sleep)
137137

138138
result = client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
139139

@@ -146,7 +146,7 @@
146146
timeout: 10
147147
)
148148
).once
149-
expect_any_instance_of(Object).not_to have_received(:sleep)
149+
expect(Kernel).not_to have_received(:sleep)
150150
end
151151

152152
it 'should return the variation id on third try with retry config' do
@@ -160,7 +160,7 @@
160160
call_sequence = [failure_response, failure_response, success_response]
161161
allow(mock_http_client).to receive(:post) { call_sequence.shift }
162162

163-
allow_any_instance_of(Object).to receive(:sleep)
163+
allow(Kernel).to receive(:sleep)
164164

165165
result = client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
166166

@@ -182,8 +182,8 @@
182182
expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 2) after 0.02 seconds...')
183183

184184
# Verify sleep was called with correct backoff times
185-
expect_any_instance_of(Object).to have_received(:sleep).with(0.01)
186-
expect_any_instance_of(Object).to have_received(:sleep).with(0.02)
185+
expect(Kernel).to have_received(:sleep).with(0.01)
186+
expect(Kernel).to have_received(:sleep).with(0.02)
187187
end
188188

189189
it 'should exhausts all retry attempts' do
@@ -194,7 +194,7 @@
194194

195195
# All attempts fail
196196
allow(mock_http_client).to receive(:post).and_return(failure_response)
197-
allow_any_instance_of(Object).to receive(:sleep)
197+
allow(Kernel).to receive(:sleep)
198198

199199
expect do
200200
client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
@@ -209,9 +209,9 @@
209209
expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 3) after 0.08 seconds...')
210210

211211
# Verify sleep was called for each retry
212-
expect_any_instance_of(Object).to have_received(:sleep).with(0.01)
213-
expect_any_instance_of(Object).to have_received(:sleep).with(0.02)
214-
expect_any_instance_of(Object).to have_received(:sleep).with(0.08)
212+
expect(Kernel).to have_received(:sleep).with(0.01)
213+
expect(Kernel).to have_received(:sleep).with(0.02)
214+
expect(Kernel).to have_received(:sleep).with(0.08)
215215

216216
# Verify final error logging
217217
expect(spy_logger).to have_received(:log).with(Logger::ERROR, a_string_including('Max retries exceeded for CMAB request'))

0 commit comments

Comments
 (0)