|
49 | 49 |
|
50 | 50 | after do
|
51 | 51 | RSpec::Mocks.space.proxy_for(spy_logger).reset
|
| 52 | + RSpec::Mocks.space.proxy_for(mock_http_client).reset_mock |
52 | 53 | end
|
53 | 54 |
|
54 | 55 | it 'should return the variation id on success without retrying' do
|
55 | 56 | client = described_class.new(mock_http_client, nil, spy_logger)
|
56 | 57 | mock_response = double('response', status_code: 200, json: {'predictions' => [{'variationId' => 'abc123'}]})
|
57 | 58 | allow(mock_http_client).to receive(:post).and_return(mock_response)
|
| 59 | + |
58 | 60 | result = client.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
| 61 | + |
59 | 62 | expect(result).to eq('abc123')
|
60 | 63 | expect(mock_http_client).to have_received(:post).with(
|
61 | 64 | expected_url,
|
|
75 | 78 | expect do
|
76 | 79 | client.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
77 | 80 | end.to raise_error(Optimizely::CmabFetchError, /Connection error/)
|
| 81 | + |
78 | 82 | expect(mock_http_client).to have_received(:post).once
|
79 | 83 | expect(spy_logger).to have_received(:log).with(Logger::ERROR, a_string_including('Connection error'))
|
80 | 84 | expect(Kernel).not_to have_received(:sleep)
|
|
183 | 187 | # Verify retry logging
|
184 | 188 | expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 1) after 0.01 seconds...').once
|
185 | 189 | 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)')) |
186 | 191 |
|
187 | 192 | # Verify sleep was called with correct backoff times
|
188 | 193 | expect(Kernel).to have_received(:sleep).with(0.01).once
|
|
197 | 202 | failure_response = double('response', status_code: 500)
|
198 | 203 |
|
199 | 204 | # 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) |
201 | 206 |
|
202 | 207 | expect do
|
203 | 208 | client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
|
0 commit comments