Skip to content

Commit

Permalink
Add test case for iter_lines method
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterKey-Pro committed Jan 9, 2025
1 parent 9d9c2e1 commit eff35bf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ def test_streaming_response_catch_response(self):
self.assertGreaterEqual(stats.avg_response_time, 0)
self.assertLess(stats.avg_response_time, 250)

def test_iter_lines(self):
"""
Test the iter_lines method for handling streaming responses.
Ensure it can process lines without verifying specific content.
"""
s = self.get_client()

# Perform the test using an actual endpoint
with s.iter_lines(url="/streaming_endpoint") as response:
if response.status_code == 200:
try:
# Simply ensure we can iterate over the lines
for line in response:
self.assertTrue(isinstance(line, str)) # Check if each part is a string
response.success() # Mark the response as successful
except Exception as e:
response.failure(f"Error processing line: {e}")
else:
response.failure(f"HTTP error: {response.status_code}")

# Verify that the statistics reflect the request was made correctly
stats = self.runner.stats.get("/streaming_endpoint", "GET")
self.assertEqual(1, stats.num_requests)
self.assertEqual(0, stats.num_failures)

def test_slow_redirect(self):
s = self.get_client()
url = "/redirect?url=/redirect&delay=0.5"
Expand Down

0 comments on commit eff35bf

Please sign in to comment.