@@ -3436,8 +3436,12 @@ def test_given_unfinished_first_parent_partition_no_parent_state_update():
3436
3436
}
3437
3437
assert mock_cursor_1 .stream_slices .call_count == 1 # Called once for each partition
3438
3438
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
+
3441
3445
3442
3446
def test_given_unfinished_last_parent_partition_with_partial_parent_state_update ():
3443
3447
# 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
3520
3524
}
3521
3525
assert mock_cursor_1 .stream_slices .call_count == 1 # Called once for each partition
3522
3526
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
3525
3532
3526
3533
3527
3534
def 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
3596
3603
assert final_state ["lookback_window" ] == 1
3597
3604
assert cursor ._message_repository .emit_message .call_count == 2
3598
3605
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
3600
3612
3601
3613
3602
3614
def test_given_partition_limit_exceeded_when_close_partition_then_switch_to_global_cursor ():
@@ -3715,18 +3727,20 @@ def test_semaphore_cleanup():
3715
3727
# Verify initial state
3716
3728
assert len (cursor ._semaphore_per_partition ) == 2
3717
3729
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" }}
3720
3734
3721
3735
# Close partitions to acquire semaphores (value back to 0)
3722
3736
for s in generated_slices :
3723
3737
cursor .close_partition (DeclarativePartition ("test_stream" , {}, MagicMock (), MagicMock (), s ))
3724
3738
3725
3739
# Check state after closing partitions
3726
- assert len (cursor ._finished_partitions ) == 2
3740
+ assert len (cursor ._finished_partitions ) == 0
3727
3741
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
3730
3744
assert len (cursor ._partition_parent_state_map ) == 0 # All parent states should be popped
3731
3745
assert cursor ._parent_state == {"parent" : {"state" : "state2" }} # Last parent state
3732
3746
0 commit comments