@@ -38,11 +38,20 @@ def test_worker_initialize_setup_success(self):
3838 self .assertIsNotNone (self .workers .response_processor )
3939
4040 def test_worker_stop_success (self ):
41- self .workers .storage .pull_all = MagicMock ()
41+ for i in range (5 ):
42+ self .workers .storage .push (BaseEvent (f"event_{ i } " , "test_user" ))
43+
44+ success_response = Response (HttpStatus .SUCCESS )
45+ HttpClient .post = MagicMock (return_value = success_response )
46+
4247 self .workers .stop ()
4348 self .assertFalse (self .workers .is_active )
4449 self .assertTrue (self .workers .is_started )
45- self .workers .storage .pull_all .assert_called_once ()
50+
51+ # Verify storage was flushed (all events removed)
52+ self .assertEqual (0 , self .workers .storage .total_events )
53+ self .assertEqual (0 , len (self .workers .storage .ready_queue ))
54+ self .assertEqual (0 , len (self .workers .storage .buffer_data ))
4655
4756 def test_worker_get_payload_success (self ):
4857 events = [BaseEvent ("test_event1" , "test_user" ), BaseEvent ("test_event2" , "test_user" )]
@@ -150,11 +159,25 @@ def test_worker_send_events_with_payload_too_large_response_decrease_flush_queue
150159 success_response = Response (HttpStatus .SUCCESS )
151160 payload_too_large_response = Response (HttpStatus .PAYLOAD_TOO_LARGE )
152161 HttpClient .post = MagicMock ()
153- HttpClient .post .side_effect = [payload_too_large_response , payload_too_large_response , success_response ]
162+ # First send gets PAYLOAD_TOO_LARGE (divider 1→2, size 30→15)
163+ # First flush sends 2 batches of 15:
164+ # - Batch 1 (15) fails: len(15) <= 15 → TRUE → increase (divider 2→3, size 15→10)
165+ # - Batch 2 (15) fails: len(15) <= 10 → FALSE → don't increase
166+ # Second flush sends 3 batches of 10, all succeed
167+ HttpClient .post .side_effect = [
168+ payload_too_large_response , # Initial send of 30 events
169+ payload_too_large_response , # First flush batch 1 (15 events)
170+ payload_too_large_response , # First flush batch 2 (15 events)
171+ success_response , # Second flush batch 1 (10 events)
172+ success_response , # Second flush batch 2 (10 events)
173+ success_response # Second flush batch 3 (10 events)
174+ ]
154175 self .workers .configuration .flush_queue_size = 30
155176 self .workers .send (events )
156177 self .assertEqual (15 , self .workers .configuration .flush_queue_size )
157178 self .workers .flush ().result ()
179+ # After first flush, only first batch increased divider (15 <= 15)
180+ # Second batch didn't (15 > 10), so divider only went 2→3
158181 self .assertEqual (10 , self .workers .configuration .flush_queue_size )
159182 self .workers .flush ().result ()
160183 self .assertEqual (30 , len (self .events_dict [200 ]))
0 commit comments