|
133 | 133 | # Mock successful response
|
134 | 134 | mock_response = double('response', status_code: 200, json: {'predictions' => [{'variationId' => 'abc123'}]})
|
135 | 135 | 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) |
137 | 137 |
|
138 | 138 | result = client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
139 | 139 |
|
|
146 | 146 | timeout: 10
|
147 | 147 | )
|
148 | 148 | ).once
|
149 |
| - expect_any_instance_of(Object).not_to have_received(:sleep) |
| 149 | + expect(Kernel).not_to have_received(:sleep) |
150 | 150 | end
|
151 | 151 |
|
152 | 152 | it 'should return the variation id on third try with retry config' do
|
|
160 | 160 | call_sequence = [failure_response, failure_response, success_response]
|
161 | 161 | allow(mock_http_client).to receive(:post) { call_sequence.shift }
|
162 | 162 |
|
163 |
| - allow_any_instance_of(Object).to receive(:sleep) |
| 163 | + allow(Kernel).to receive(:sleep) |
164 | 164 |
|
165 | 165 | result = client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
166 | 166 |
|
|
182 | 182 | expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 2) after 0.02 seconds...')
|
183 | 183 |
|
184 | 184 | # 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) |
187 | 187 | end
|
188 | 188 |
|
189 | 189 | it 'should exhausts all retry attempts' do
|
|
194 | 194 |
|
195 | 195 | # All attempts fail
|
196 | 196 | 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) |
198 | 198 |
|
199 | 199 | expect do
|
200 | 200 | client_with_retry.fetch_decision(rule_id, user_id, attributes, cmab_uuid)
|
|
209 | 209 | expect(spy_logger).to have_received(:log).with(Logger::INFO, 'Retrying CMAB request (attempt 3) after 0.08 seconds...')
|
210 | 210 |
|
211 | 211 | # 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) |
215 | 215 |
|
216 | 216 | # Verify final error logging
|
217 | 217 | expect(spy_logger).to have_received(:log).with(Logger::ERROR, a_string_including('Max retries exceeded for CMAB request'))
|
|
0 commit comments