Skip to content

Commit 8a0a8ae

Browse files
committed
test: update tests to reflect response.close() cleanup
Updated test assertions to verify response.close() is called instead of decoder.close(), aligning with review feedback. Changes: - NewImplementationSimulator now calls response.close() - Stream cleanup test verifies response.close() - Regression test verifies response.close() All 11 tests now pass with live API validation.
1 parent 568417a commit 8a0a8ae

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

β€Žtests/lib/streaming/test_streaming_sdk_performance.pyβ€Ž

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
Β (0)