Skip to content

Commit c934da1

Browse files
committed
please save me from the madness
1 parent 5d41f4e commit c934da1

File tree

1 file changed

+31
-0
lines changed
  • airbyte_cdk/sources/streams/concurrent

1 file changed

+31
-0
lines changed

airbyte_cdk/sources/streams/concurrent/cursor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import functools
66
import logging
7+
import os
78
from abc import ABC, abstractmethod
89
from typing import (
910
Any,
@@ -17,6 +18,7 @@
1718
Union,
1819
)
1920

21+
from airbyte_cdk.models import AirbyteLogMessage, AirbyteMessage, Level, Type
2022
from airbyte_cdk.sources.connector_state_manager import ConnectorStateManager
2123
from airbyte_cdk.sources.message import MessageRepository
2224
from airbyte_cdk.sources.streams import NO_CURSOR_STATE_KEY
@@ -237,12 +239,41 @@ def _extract_cursor_value(self, record: Record) -> Any:
237239
return self._connector_state_converter.parse_value(self._cursor_field.extract_value(record))
238240

239241
def close_partition(self, partition: Partition) -> None:
242+
test_env = os.getenv("PYTEST_CURRENT_TEST")
243+
if test_env and "test_concurrent_declarative_source.py" in test_env:
244+
self._message_repository.emit_message(
245+
AirbyteMessage(
246+
type=Type.LOG,
247+
log=AirbyteLogMessage(
248+
level=Level.INFO, message=f"Closing partition {partition.to_slice()}"
249+
),
250+
)
251+
)
252+
self._message_repository.emit_message(
253+
AirbyteMessage(
254+
type=Type.LOG,
255+
log=AirbyteLogMessage(
256+
level=Level.INFO, message=f"\tstate before is {self._concurrent_state}"
257+
),
258+
)
259+
)
260+
240261
slice_count_before = len(self._concurrent_state.get("slices", []))
241262
self._add_slice_to_state(partition)
242263
if slice_count_before < len(
243264
self._concurrent_state["slices"]
244265
): # only emit if at least one slice has been processed
245266
self._merge_partitions()
267+
if test_env and "test_concurrent_declarative_source.py" in test_env:
268+
self._message_repository.emit_message(
269+
AirbyteMessage(
270+
type=Type.LOG,
271+
log=AirbyteLogMessage(
272+
level=Level.INFO,
273+
message=f"\tstate after merged partition is {self._concurrent_state}",
274+
),
275+
)
276+
)
246277
self._emit_state_message()
247278
self._has_closed_at_least_one_slice = True
248279

0 commit comments

Comments
 (0)