本文整理汇总了Python中locust.stats.RequestStats.serialize_stats方法的典型用法代码示例。如果您正苦于以下问题:Python RequestStats.serialize_stats方法的具体用法?Python RequestStats.serialize_stats怎么用?Python RequestStats.serialize_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locust.stats.RequestStats
的用法示例。
在下文中一共展示了RequestStats.serialize_stats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_master_total_stats
# 需要导入模块: from locust.stats import RequestStats [as 别名]
# 或者: from locust.stats.RequestStats import serialize_stats [as 别名]
def test_master_total_stats(self):
import mock
class MyTestLocust(Locust):
pass
with mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()) as server:
master = MasterLocustRunner(MyTestLocust, self.options)
server.mocked_send(Message("client_ready", None, "fake_client"))
stats = RequestStats()
stats.log_request("GET", "/1", 100, 3546)
stats.log_request("GET", "/1", 800, 56743)
stats2 = RequestStats()
stats2.log_request("GET", "/2", 700, 2201)
server.mocked_send(Message("stats", {
"stats":stats.serialize_stats(),
"stats_total": stats.total.serialize(),
"errors":stats.serialize_errors(),
"user_count": 1,
}, "fake_client"))
server.mocked_send(Message("stats", {
"stats":stats2.serialize_stats(),
"stats_total": stats2.total.serialize(),
"errors":stats2.serialize_errors(),
"user_count": 2,
}, "fake_client"))
self.assertEqual(700, master.stats.total.median_response_time)
示例2: test_master_current_response_times
# 需要导入模块: from locust.stats import RequestStats [as 别名]
# 或者: from locust.stats.RequestStats import serialize_stats [as 别名]
def test_master_current_response_times(self):
import mock
class MyTestLocust(Locust):
pass
start_time = 1
with mock.patch("time.time") as mocked_time:
mocked_time.return_value = start_time
global_stats.reset_all()
with mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()) as server:
master = MasterLocustRunner(MyTestLocust, self.options)
mocked_time.return_value += 1
server.mocked_send(Message("client_ready", None, "fake_client"))
stats = RequestStats()
stats.log_request("GET", "/1", 100, 3546)
stats.log_request("GET", "/1", 800, 56743)
server.mocked_send(Message("stats", {
"stats":stats.serialize_stats(),
"stats_total": stats.total.get_stripped_report(),
"errors":stats.serialize_errors(),
"user_count": 1,
}, "fake_client"))
mocked_time.return_value += 1
stats2 = RequestStats()
stats2.log_request("GET", "/2", 400, 2201)
server.mocked_send(Message("stats", {
"stats":stats2.serialize_stats(),
"stats_total": stats2.total.get_stripped_report(),
"errors":stats2.serialize_errors(),
"user_count": 2,
}, "fake_client"))
mocked_time.return_value += 4
self.assertEqual(400, master.stats.total.get_current_response_time_percentile(0.5))
self.assertEqual(800, master.stats.total.get_current_response_time_percentile(0.95))
# let 10 second pass, do some more requests, send it to the master and make
# sure the current response time percentiles only accounts for these new requests
mocked_time.return_value += 10
stats.log_request("GET", "/1", 20, 1)
stats.log_request("GET", "/1", 30, 1)
stats.log_request("GET", "/1", 3000, 1)
server.mocked_send(Message("stats", {
"stats":stats.serialize_stats(),
"stats_total": stats.total.get_stripped_report(),
"errors":stats.serialize_errors(),
"user_count": 2,
}, "fake_client"))
self.assertEqual(30, master.stats.total.get_current_response_time_percentile(0.5))
self.assertEqual(3000, master.stats.total.get_current_response_time_percentile(0.95))