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 78753c5 commit d470be5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ def test_iter_lines(self):
"""
s = self.get_client()

# Use the actual endpoint to test streaming response
response = s.iter_lines(url="/streaming_endpoint")
with s.get("/streaming/30", stream=True, catch_response=True) as r:
if r.status_code == 200:
try:
# Iterate over lines using the streaming response
for line in r.iter_lines():
self.assertTrue(isinstance(line, str)) # Check if each line is a string
r.success() # Mark the response as successful
except Exception as e:
r.failure(f"Error processing line: {e}")
else:
r.failure(f"HTTP error: {r.status_code}")

try:
# Ensure we can iterate over the lines returned by the generator
for line in response:
self.assertTrue(isinstance(line, str)) # Check if each line is a string
# Optionally, mark the request as successful if needed
except Exception as e:
# Handle any exceptions that occur during iteration
self.fail(f"Error processing line: {e}")

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

Expand Down

0 comments on commit d470be5

Please sign in to comment.