@@ -3436,8 +3436,12 @@ def test_given_unfinished_first_parent_partition_no_parent_state_update():
34363436 }
34373437 assert mock_cursor_1 .stream_slices .call_count == 1 # Called once for each partition
34383438 assert mock_cursor_2 .stream_slices .call_count == 1 # Called once for each partition
3439- assert len (cursor ._semaphore_per_partition ) == 1 # Semaphore cleaned after partiton is completed
3440- # ToDo: Add check for other interal values
3439+
3440+ assert len (cursor ._semaphore_per_partition ) == 1
3441+ assert len (cursor ._finished_partitions ) == 1
3442+ assert len (cursor ._open_seqs ) == 1
3443+ assert len (cursor ._seq_by_partition ) == 1
3444+
34413445
34423446def test_given_unfinished_last_parent_partition_with_partial_parent_state_update ():
34433447 # Create two mock cursors with different states for each partition
@@ -3520,8 +3524,11 @@ def test_given_unfinished_last_parent_partition_with_partial_parent_state_update
35203524 }
35213525 assert mock_cursor_1 .stream_slices .call_count == 1 # Called once for each partition
35223526 assert mock_cursor_2 .stream_slices .call_count == 1 # Called once for each partition
3523- assert len (cursor ._semaphore_per_partition ) == 0
3524- # ToDo: Add check for other interal values
3527+
3528+ assert len (cursor ._semaphore_per_partition ) == 1
3529+ assert len (cursor ._finished_partitions ) == 1
3530+ assert len (cursor ._open_seqs ) == 1
3531+ assert len (cursor ._seq_by_partition ) == 1
35253532
35263533
35273534def test_given_all_partitions_finished_when_close_partition_then_final_state_emitted ():
@@ -3596,7 +3603,12 @@ def test_given_all_partitions_finished_when_close_partition_then_final_state_emi
35963603 assert final_state ["lookback_window" ] == 1
35973604 assert cursor ._message_repository .emit_message .call_count == 2
35983605 assert mock_cursor .stream_slices .call_count == 2 # Called once for each partition
3599- assert len (cursor ._semaphore_per_partition ) == 1
3606+
3607+ # Checks that all internal variables are cleaned up
3608+ assert len (cursor ._semaphore_per_partition ) == 0
3609+ assert len (cursor ._finished_partitions ) == 0
3610+ assert len (cursor ._open_seqs ) == 0
3611+ assert len (cursor ._seq_by_partition ) == 0
36003612
36013613
36023614def test_given_partition_limit_exceeded_when_close_partition_then_switch_to_global_cursor ():
@@ -3715,18 +3727,20 @@ def test_semaphore_cleanup():
37153727 # Verify initial state
37163728 assert len (cursor ._semaphore_per_partition ) == 2
37173729 assert len (cursor ._partition_parent_state_map ) == 2
3718- assert cursor ._partition_parent_state_map ['{"id":"1"}' ] == {"parent" : {"state" : "state1" }}
3719- assert cursor ._partition_parent_state_map ['{"id":"2"}' ] == {"parent" : {"state" : "state2" }}
3730+ assert len (cursor ._open_seqs ) == 2
3731+ assert len (cursor ._seq_by_partition ) == 2
3732+ assert cursor ._partition_parent_state_map ['{"id":"1"}' ][0 ] == {"parent" : {"state" : "state1" }}
3733+ assert cursor ._partition_parent_state_map ['{"id":"2"}' ][0 ] == {"parent" : {"state" : "state2" }}
37203734
37213735 # Close partitions to acquire semaphores (value back to 0)
37223736 for s in generated_slices :
37233737 cursor .close_partition (DeclarativePartition ("test_stream" , {}, MagicMock (), MagicMock (), s ))
37243738
37253739 # Check state after closing partitions
3726- assert len (cursor ._finished_partitions ) == 2
3740+ assert len (cursor ._finished_partitions ) == 0
37273741 assert len (cursor ._semaphore_per_partition ) == 0
3728- assert '{"id":"1"}' not in cursor ._semaphore_per_partition
3729- assert '{"id":"2"}' not in cursor ._semaphore_per_partition
3742+ assert len ( cursor ._open_seqs ) == 0
3743+ assert len ( cursor ._seq_by_partition ) == 0
37303744 assert len (cursor ._partition_parent_state_map ) == 0 # All parent states should be popped
37313745 assert cursor ._parent_state == {"parent" : {"state" : "state2" }} # Last parent state
37323746
0 commit comments