Skip to content

Commit 28f30e0

Browse files
committed
Fix
1 parent 5fdbf80 commit 28f30e0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spec/cmab_client_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@
4949

5050
after do
5151
RSpec::Mocks.space.proxy_for(spy_logger).reset
52+
RSpec::Mocks.space.proxy_for(mock_http_client).reset_mock
5253
end
5354

5455
it 'should return the variation id on success without retrying' do
5556
client = described_class.new(mock_http_client, nil, spy_logger)
5657
mock_response = double('response', status_code: 200, json: {'predictions' => [{'variationId' => 'abc123'}]})
5758
allow(mock_http_client).to receive(:post).and_return(mock_response)
59+
5860
result = client.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
61+
5962
expect(result).to eq('abc123')
6063
expect(mock_http_client).to have_received(:post).with(
6164
expected_url,
@@ -75,6 +78,7 @@
7578
expect do
7679
client.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
7780
end.to raise_error(Optimizely::CmabFetchError, /Connection error/)
81+
7882
expect(mock_http_client).to have_received(:post).once
7983
expect(spy_logger).to have_received(:log).with(Logger::ERROR, a_string_including('Connection error'))
8084
expect(Kernel).not_to have_received(:sleep)
@@ -183,6 +187,7 @@
183187
# Verify retry logging
184188
expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 1) after 0.01 seconds...').once
185189
expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 2) after 0.02 seconds...').once
190+
expect(spy_logger).not_to have_received(:log).with(Logger::INFO, a_string_including('Retrying CMAB request (attempt 3)'))
186191

187192
# Verify sleep was called with correct backoff times
188193
expect(Kernel).to have_received(:sleep).with(0.01).once
@@ -197,7 +202,7 @@
197202
failure_response = double('response', status_code: 500)
198203

199204
# All attempts fail
200-
allow(mock_http_client).to receive(:post).and_return(failure_response)
205+
allow(mock_http_client).to receive(:post).and_return(failure_response, failure_response, failure_response, failure_response)
201206

202207
expect do
203208
client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)

0 commit comments

Comments
 (0)