|
8 | 8 | import ujson |
9 | 9 | from django.db import DatabaseError |
10 | 10 | from pika.adapters.utils.connection_workflow import AMQPConnectorException |
11 | | -from pika.exceptions import AMQPError, ChannelError, ReentrancyError |
| 11 | +from pika.exceptions import ( |
| 12 | + AMQPError, |
| 13 | + ChannelError, |
| 14 | + ReentrancyError, |
| 15 | + StreamLostError, |
| 16 | +) |
12 | 17 |
|
13 | 18 | from dj_cqrs.constants import ( |
14 | 19 | DEFAULT_MASTER_AUTO_UPDATE_FIELDS, |
@@ -223,8 +228,47 @@ def test_produce_retry_on_error(rabbit_transport, mocker, caplog): |
223 | 228 | SignalType.SAVE, 'CQRS_ID', {'id': 1}, 1, |
224 | 229 | ), |
225 | 230 | ) |
226 | | - assert "CQRS couldn't be published: pk = 1 (CQRS_ID). Reconnect..." in caplog.text |
227 | | - assert 'CQRS is published: pk = 1 (CQRS_ID)' in caplog.text |
| 231 | + |
| 232 | + assert caplog.record_tuples == [ |
| 233 | + ( |
| 234 | + 'django-cqrs', |
| 235 | + logging.WARNING, |
| 236 | + "CQRS couldn't be published: pk = 1 (CQRS_ID)." |
| 237 | + " Error: AMQPConnectorException. Reconnect...", |
| 238 | + ), |
| 239 | + ( |
| 240 | + 'django-cqrs', |
| 241 | + logging.INFO, |
| 242 | + 'CQRS is published: pk = 1 (CQRS_ID), correlation_id = None.', |
| 243 | + ), |
| 244 | + ] |
| 245 | + |
| 246 | + |
| 247 | +def test_produce_retry_on_error_1(rabbit_transport, mocker, caplog): |
| 248 | + mocker.patch.object(RabbitMQTransport, '_get_producer_rmq_objects', side_effect=[ |
| 249 | + StreamLostError, |
| 250 | + StreamLostError, |
| 251 | + ]) |
| 252 | + mocker.patch.object(RabbitMQTransport, '_produce_message', return_value=True) |
| 253 | + |
| 254 | + rabbit_transport.produce( |
| 255 | + TransportPayload( |
| 256 | + SignalType.SAVE, 'CQRS_ID', {'id': 1}, 1, |
| 257 | + ), |
| 258 | + ) |
| 259 | + |
| 260 | + assert caplog.record_tuples == [ |
| 261 | + ( |
| 262 | + 'django-cqrs', |
| 263 | + logging.WARNING, |
| 264 | + "CQRS couldn't be published: pk = 1 (CQRS_ID). Error: StreamLostError. Reconnect...", |
| 265 | + ), |
| 266 | + ( |
| 267 | + 'django-cqrs', |
| 268 | + logging.ERROR, |
| 269 | + "CQRS couldn't be published: pk = 1 (CQRS_ID).", |
| 270 | + ), |
| 271 | + ] |
228 | 272 |
|
229 | 273 |
|
230 | 274 | def test_produce_message_ok(mocker): |
|
0 commit comments