@@ -45,10 +45,9 @@ def new_event_type_check(event_type):
4545 return event_type in MESSAGE_EVENTS
4646
4747 @staticmethod
48- def new_stream_cleanup (decoder ):
49- """Simulate new efficient cleanup by closing decoder resources"""
50- if hasattr (decoder , "close" ):
51- decoder .close ()
48+ def new_stream_cleanup (response ):
49+ """Simulate new efficient cleanup by closing response directly"""
50+ response .close ()
5251 return 0 # No events consumed
5352
5453
@@ -466,20 +465,19 @@ def test_stream_cleanup_efficiency(self):
466465 print (f" Rate: { old_consumed / old_cleanup_time :.0f} events/sec" )
467466
468467 # Simulate NEW cleanup approach (just call close)
469- print (f"\n β‘ Testing NEW approach (direct decoder close)..." )
470- mock_decoder = Mock ()
471- mock_decoder .close = Mock ()
468+ print (f"\n β‘ Testing NEW approach (direct response close)..." )
469+ mock_response = Mock ()
470+ mock_response .close = Mock ()
472471
473472 new_start = time .perf_counter ()
474473 # Simulate the actual new cleanup logic
475- if hasattr (mock_decoder , "close" ):
476- mock_decoder .close ()
474+ mock_response .close ()
477475 new_consumed = 0 # No events consumed
478476 new_cleanup_time = time .perf_counter () - new_start
479477
480478 print (f" Time taken: { new_cleanup_time :.6f} s" )
481479 print (f" Events consumed: { new_consumed } " )
482- print (f" Method called: decoder .close()" )
480+ print (f" Method called: response .close()" )
483481
484482 # Print comparison results
485483 print (f"\n π Stream Cleanup Efficiency Comparison:" )
@@ -505,8 +503,8 @@ def test_stream_cleanup_efficiency(self):
505503 assert old_consumed == num_events , "Old approach should consume all remaining events"
506504 print (f" β
Old approach consumes all { num_events :,} events - PASSED" )
507505
508- mock_decoder .close .assert_called_once ()
509- print (f" β
Decoder .close() was called - PASSED" )
506+ mock_response .close .assert_called_once ()
507+ print (f" β
Response .close() was called - PASSED" )
510508
511509 print (f" π STREAM CLEANUP TEST PASSED" )
512510 print (f" π Summary: NEW approach eliminates { old_consumed :,} unnecessary operations" )
@@ -729,8 +727,8 @@ def mock_process_response_data(*args, **kwargs):
729727 if isinstance (event , dict ):
730728 assert "type" in event
731729
732- # Verify cleanup
733- mock_decoder .close .assert_called_once ()
730+ # Verify cleanup - response.close() should be called (not decoder.close())
731+ mock_response .close .assert_called_once ()
734732
735733 print (f"\n π Regression Test Results:" )
736734 print (f" Total events: { len (events )} " )
0 commit comments