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 10, 2025
1 parent 9d7de6b commit 96662d3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,23 @@ def test_streaming_response_catch_response(self):
self.assertLess(stats.avg_response_time, 250)

def test_iter_lines(self):
# Create a mock user or use an actual user class if available
# 使用 MagicMock 创建环境和用户
mock_environment = MagicMock()
mock_user = MagicMock()

# Initialize FastHttpSession with the local server and mock user
session = FastHttpSession(self.environment, user=mock_user, base_url=f"http://127.0.0.1:{self.port}")
# 初始化 FastHttpSession,确保所有参数都被正确传递
session = FastHttpSession(mock_environment, user=mock_user, base_url=f"http://127.0.0.1:{self.port}")

# Make a request to the /streaming endpoint with a specific number of iterations
# 指定请求的 URL,使用 /streaming/10 来测试流式响应
url = "/streaming/10"

# Use the iter_lines method to read the streamed response
# 使用 iter_lines 方法读取流式响应
lines = list(session.iter_lines(url))

# Define the expected lines based on the number of iterations
# 根据 iterations 参数定义预期的响应行
expected_lines = [f"<span>{i}</span>" for i in range(10)]

# Validate the response lines
# 断言响应行与预期一致
self.assertEqual(lines, expected_lines)

def test_slow_redirect(self):
Expand Down

0 comments on commit 96662d3

Please sign in to comment.