1414 _CGROUP_V1_USAGE ,
1515 _CGROUP_V2_CURRENT ,
1616 _CGROUP_V2_MAX ,
17- MemoryLimitExceeded ,
1817 MemoryMonitor ,
1918)
19+ from airbyte_cdk .utils .traced_exception import AirbyteTracedException
2020
2121_MOCK_USAGE_BELOW = "500000000\n " # 50% of 1 GB
2222_MOCK_USAGE_WARNING = "870000000\n " # 87% of 1 GB
@@ -160,27 +160,27 @@ def test_custom_thresholds_warning(caplog: pytest.LogCaptureFixture) -> None:
160160
161161
162162def test_critical_at_95_percent_raises () -> None :
163- """MemoryLimitExceeded should be raised at 96% usage."""
163+ """AirbyteTracedException should be raised at 96% usage."""
164164 monitor = MemoryMonitor (check_interval = 1 )
165165 with (
166166 patch .object (Path , "exists" , _v2_exists ),
167167 patch .object (Path , "read_text" , _v2_mock_read (usage = _MOCK_USAGE_CRITICAL )),
168168 ):
169- with pytest .raises (MemoryLimitExceeded ) as exc_info :
169+ with pytest .raises (AirbyteTracedException ) as exc_info :
170170 monitor .check_memory_usage ()
171171
172172 assert exc_info .value .failure_type == FailureType .system_error
173173 assert "96%" in (exc_info .value .message or "" )
174174
175175
176176def test_critical_raised_only_once () -> None :
177- """MemoryLimitExceeded should only be raised once."""
177+ """AirbyteTracedException should only be raised once."""
178178 monitor = MemoryMonitor (check_interval = 1 )
179179 with (
180180 patch .object (Path , "exists" , _v2_exists ),
181181 patch .object (Path , "read_text" , _v2_mock_read (usage = _MOCK_USAGE_CRITICAL )),
182182 ):
183- with pytest .raises (MemoryLimitExceeded ):
183+ with pytest .raises (AirbyteTracedException ):
184184 monitor .check_memory_usage ()
185185 # Second call should NOT raise again
186186 monitor .check_memory_usage ()
@@ -197,7 +197,7 @@ def test_custom_thresholds_critical() -> None:
197197 patch .object (Path , "exists" , _v2_exists ),
198198 patch .object (Path , "read_text" , _v2_mock_read (usage = "850000000\n " )),
199199 ):
200- with pytest .raises (MemoryLimitExceeded ):
200+ with pytest .raises (AirbyteTracedException ):
201201 monitor .check_memory_usage ()
202202
203203
@@ -293,32 +293,3 @@ def mock_read_text(self: Path) -> str:
293293 ):
294294 monitor .check_memory_usage ()
295295 assert not caplog .records
296-
297-
298- # ---------------------------------------------------------------------------
299- # MemoryLimitExceeded exception
300- # ---------------------------------------------------------------------------
301-
302-
303- def test_memory_limit_exceeded_is_airbyte_traced_exception () -> None :
304- """MemoryLimitExceeded should be a subclass of AirbyteTracedException."""
305- from airbyte_cdk .utils .traced_exception import AirbyteTracedException
306-
307- exc = MemoryLimitExceeded (
308- internal_message = "test" ,
309- message = "test message" ,
310- failure_type = FailureType .system_error ,
311- )
312- assert isinstance (exc , AirbyteTracedException )
313-
314-
315- def test_memory_limit_exceeded_attributes () -> None :
316- """MemoryLimitExceeded should have correct attributes."""
317- exc = MemoryLimitExceeded (
318- internal_message = "Memory at 96%" ,
319- message = "Source exceeded memory limit." ,
320- failure_type = FailureType .system_error ,
321- )
322- assert exc .failure_type == FailureType .system_error
323- assert exc .message == "Source exceeded memory limit."
324- assert exc .internal_message == "Memory at 96%"
0 commit comments