|
24 | 24 | from databento.common.constants import SCHEMA_STRUCT_MAP |
25 | 25 | from databento.common.cram import BUCKET_ID_LENGTH |
26 | 26 | from databento.common.dbnstore import DBNStore |
| 27 | +from databento.common.enums import SlowReadBehavior |
27 | 28 | from databento.common.error import BentoError |
28 | 29 | from databento.common.publishers import Dataset |
29 | 30 | from databento.live import client |
@@ -331,6 +332,50 @@ async def test_live_connect_auth_with_heartbeat_interval( |
331 | 332 | assert message.heartbeat_interval_s == "10" |
332 | 333 |
|
333 | 334 |
|
| 335 | +@pytest.mark.parametrize( |
| 336 | + "slow_reader_behavior", |
| 337 | + [b for b in SlowReadBehavior], |
| 338 | +) |
| 339 | +async def test_live_connect_auth_with_slow_reader_behavior( |
| 340 | + mock_live_server: MockLiveServerInterface, |
| 341 | + test_live_api_key: str, |
| 342 | + slow_reader_behavior: SlowReadBehavior, |
| 343 | +) -> None: |
| 344 | + """ |
| 345 | + Test that setting `slow_reader_behavior` on a Live client sends that field |
| 346 | + to the gateway. |
| 347 | + """ |
| 348 | + # Arrange |
| 349 | + live_client = client.Live( |
| 350 | + key=test_live_api_key, |
| 351 | + gateway=mock_live_server.host, |
| 352 | + port=mock_live_server.port, |
| 353 | + heartbeat_interval_s=10, |
| 354 | + slow_reader_behavior=slow_reader_behavior, |
| 355 | + ) |
| 356 | + |
| 357 | + live_client.subscribe( |
| 358 | + dataset=Dataset.GLBX_MDP3, |
| 359 | + schema=Schema.MBO, |
| 360 | + ) |
| 361 | + |
| 362 | + # Act |
| 363 | + message = await mock_live_server.wait_for_message_of_type( |
| 364 | + message_type=gateway.AuthenticationRequest, |
| 365 | + ) |
| 366 | + |
| 367 | + # Assert |
| 368 | + assert message.auth.endswith(live_client.key[-BUCKET_ID_LENGTH:]) |
| 369 | + assert message.dataset == live_client.dataset |
| 370 | + assert message.encoding == Encoding.DBN |
| 371 | + |
| 372 | + # Temporary handling of renamed variant |
| 373 | + if slow_reader_behavior == SlowReadBehavior.SKIP: |
| 374 | + assert message.slow_reader_behavior == "drop" |
| 375 | + else: |
| 376 | + assert message.slow_reader_behavior == slow_reader_behavior |
| 377 | + |
| 378 | + |
334 | 379 | async def test_live_connect_auth_two_clients( |
335 | 380 | mock_live_server: MockLiveServerInterface, |
336 | 381 | test_live_api_key: str, |
|
0 commit comments