@@ -908,11 +908,11 @@ def _raise_on_second_call() -> None:
908908 for msg in entrypoint .run (parsed_args ):
909909 messages .append (msg )
910910
911- # 1. Only the first record was yielded; the second triggered the exception
912- # before its yield so it is handled in the finally block instead .
911+ # 1. Both records were yielded before the exception — the memory check
912+ # runs after yield so every message pulled from the source is emitted .
913913 record_messages = [m for m in messages if "RECORD" in m ]
914- assert len (record_messages ) >= 1 , (
915- "At least the first record should be yielded before MemoryLimitExceeded"
914+ assert len (record_messages ) == 2 , (
915+ "Both records should be yielded before MemoryLimitExceeded"
916916 )
917917
918918 # 2. The queued state message was flushed by the finally block
@@ -922,11 +922,10 @@ def _raise_on_second_call() -> None:
922922 )
923923
924924 # 3. The flushed state has sourceStats.recordCount set by handle_record_counts.
925- # Only the first record is yielded (and counted) because the memory check
926- # now runs *before* yield — the second check raises before the second
927- # record is handled, so the counter is 1.0 at flush time.
925+ # Both records are yielded (and counted) before the second check_memory_usage
926+ # raises, so the counter is 2.0 at flush time.
928927 state_json = orjson .loads (state_messages [0 ])
929- assert state_json ["state" ]["sourceStats" ]["recordCount" ] == 1 .0
928+ assert state_json ["state" ]["sourceStats" ]["recordCount" ] == 2 .0
930929
931930
932931def test_given_serialization_error_using_orjson_then_fallback_on_json (
0 commit comments