Skip to content

Commit 8a971f3

Browse files
committed
adding lots of logging to diagnose flaky test
1 parent eb824f4 commit 8a971f3

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

airbyte_cdk/sources/concurrent_source/concurrent_read_processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44
import logging
5+
import os
56
from typing import Dict, Iterable, List, Optional, Set
67

78
from airbyte_cdk.exception_handler import generate_failed_streams_error_message
@@ -154,6 +155,9 @@ def on_record(self, record: Record) -> Iterable[AirbyteMessage]:
154155
)
155156
self._record_counter[stream.name] += 1
156157
stream.cursor.observe(record)
158+
test_env = os.getenv("PYTEST_CURRENT_TEST")
159+
if test_env and "test_concurrent_declarative_source.py" in test_env:
160+
self._logger.info(f"Processing and emitting: {message.__dict__}")
157161
yield message
158162
yield from self._message_repository.consume_queue()
159163

airbyte_cdk/sources/message/concurrent_repository.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
2-
2+
import logging
3+
import os
34
from queue import Queue
45
from typing import Callable, Iterable
56

67
from airbyte_cdk.models import AirbyteMessage, Level
8+
from airbyte_cdk.models import Type as MessageType
79
from airbyte_cdk.sources.message.repository import LogMessage, MessageRepository
810
from airbyte_cdk.sources.streams.concurrent.partitions.types import QueueItem
911

12+
logger = logging.getLogger("airbyte")
13+
1014

1115
class ConcurrentMessageRepository(MessageRepository):
1216
"""
@@ -25,14 +29,25 @@ def __init__(self, queue: Queue[QueueItem], message_repository: MessageRepositor
2529
self._queue = queue
2630
self._decorated_message_repository = message_repository
2731

32+
test_env = os.getenv("PYTEST_CURRENT_TEST")
33+
self._log_messages_for_testing = (
34+
test_env and "test_concurrent_declarative_source.py" in test_env
35+
)
36+
2837
def emit_message(self, message: AirbyteMessage) -> None:
38+
if self._log_messages_for_testing:
39+
self._log_message(message)
2940
self._decorated_message_repository.emit_message(message)
3041
for message in self._decorated_message_repository.consume_queue():
42+
if self._log_messages_for_testing:
43+
self._log_message(message)
3144
self._queue.put(message)
3245

3346
def log_message(self, level: Level, message_provider: Callable[[], LogMessage]) -> None:
3447
self._decorated_message_repository.log_message(level, message_provider)
3548
for message in self._decorated_message_repository.consume_queue():
49+
if self._log_messages_for_testing:
50+
self._log_message(message)
3651
self._queue.put(message)
3752

3853
def consume_queue(self) -> Iterable[AirbyteMessage]:
@@ -41,3 +56,16 @@ def consume_queue(self) -> Iterable[AirbyteMessage]:
4156
loading messages onto the queue processed on the main thread.
4257
"""
4358
yield from []
59+
60+
@staticmethod
61+
def _log_message(message: AirbyteMessage) -> None:
62+
if message.type == MessageType.STATE:
63+
if message.state and message.state.stream:
64+
state = message.state.stream.stream_state.__dict__
65+
logger.info(
66+
f"Processing and emitting message of type {message.type} with contents: {message.state.stream.stream_state.__dict__}"
67+
)
68+
else:
69+
logger.info(
70+
f"Processing and emitting message of type {message.type} with contents: {message.__dict__}"
71+
)

unit_tests/sources/declarative/test_concurrent_declarative_source.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,8 @@ def test_read_concurrent_with_failing_partition_in_the_middle():
15071507
):
15081508
messages.append(message)
15091509
except AirbyteTracedException:
1510+
locations_states = get_states_for_stream(stream_name="locations", messages=messages)
1511+
assert len(locations_states) == 3
15101512
assert (
15111513
get_states_for_stream(stream_name="locations", messages=messages)[
15121514
-1

0 commit comments

Comments
 (0)