【问题标题】:Locust.io setup, teardown not executedLocust.io 设置,未执行拆卸
【发布时间】:2018-03-22 22:40:27
【问题描述】:

我正在尝试了解蝗虫测试中的流程。我已经设置了这个非常简单的任务集和用户:

from locust import TaskSet, HttpLocust, task

class BlazeDemoTaskSet(TaskSet):

    def setup(self):
        print("hello from taskset setup")

    def teardown(self):
        print("hello from taskset teardown")

    def on_start(self):
        print("hello from taskset on_start")

    def on_stop(self):
        print("hello from taskset on_stop")

    @task
    def reserve_task(self):
        post_response = self.client.post(
            url="/reserve.php", 
            params={"toPort":"Buenos Aries", "fromPort":"Paris"})


class BlazeDemoUser(HttpLocust):
    task_set = BlazeDemoTaskSet
    min_wait = 500
    max_wait = 1500
    host = "http://www.blazedemo.com"

    def setup(self):
        print("hello from httplocust setup")

    def teardown(self):
        print("hello from httplocust teardown")

我运行它:

locust -f tests/blazedemo.py --no-web -c 1 -r 1 -n 2

我没有看到正在执行的 HttpLocust setupteardown 方法,也没有看到正在执行的 TaskSet setupon_stopteardown 方法。唯一可以运行的方法是 on_startreserve_task

According to the docs 所有这些方法都应该运行。每次运行都设置和拆卸一次,并且为每个启动的用户设置 on_start 和 on_stop。

这是 Locust 的全部输出:

[2018-03-22 18:26:50,698] C02PV7NSG8WP/INFO/locust.main: Starting Locust 0.8.1
[2018-03-22 18:26:50,698] C02PV7NSG8WP/INFO/locust.runners: Hatching and swarming 1 clients at the rate 1 clients/s...
 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                              0     0(0.00%)                                       0.00

[2018-03-22 18:26:50,699] C02PV7NSG8WP/INFO/stdout: hello from taskset on_start
[2018-03-22 18:26:50,699] C02PV7NSG8WP/INFO/stdout: 
[2018-03-22 18:26:51,703] C02PV7NSG8WP/INFO/locust.runners: All locusts hatched: BlazeDemoUser: 1
[2018-03-22 18:26:51,703] C02PV7NSG8WP/INFO/locust.runners: Resetting stats

 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
 POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris               1     0(0.00%)     140     140     140  |     140    0.00
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                              1     0(0.00%)                                       0.00

[2018-03-22 18:26:53,268] C02PV7NSG8WP/INFO/locust.runners: All locusts dead

[2018-03-22 18:26:53,268] C02PV7NSG8WP/INFO/locust.main: Shutting down (exit code 0), bye.
 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
 POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris               2     0(0.00%)     139     139     140  |     140    0.00
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                              2     0(0.00%)                                       0.00

Percentage of the requests completed within given times
 Name                                                           # reqs    50%    66%    75%    80%    90%    95%    98%    99%   100%
--------------------------------------------------------------------------------------------------------------------------------------------
 POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris                2    140    140    140    140    140    140    140    140    140
--------------------------------------------------------------------------------------------------------------------------------------------

我错过了什么?提前谢谢!

【问题讨论】:

    标签: locust


    【解决方案1】:

    Locust.setupLocust.teardownTaskSet.setupTaskSet.teardown 挂钩已在 1.0 版中移除。描述可以在docs找到。

    test_starttest_stop 事件可用于为 >= 1.0 的版本实现相同的功能

    来自文档:

    from locust import events
    
    @events.test_start.add_listener
    def on_test_start(**kw):
        print("test is starting")
    
    @events.test_stop.add_listener
    def on_test_stop(**kw):
        print("test is stopping")
    

    【讨论】:

      【解决方案2】:

      根据文档,所有这些方法都应该运行。

      此功能在 PyPI 的最新稳定版本(当前为 0.8.1)中尚不可用。 setup/terdown 支持最近被合并,将在 0.9 版中发布。现在,您必须从 locustio Git repo 安装 master 分支才能使用这些。

      从主机安装:

      任一运行:

      • pip install -e git+https://github.com/locustio/locust.git@master#egg=locustio

      或者克隆 git repo,然后运行:

      • pip install -e .

      【讨论】:

      • 仅供参考,最新稳定版本的文档可在此处获得:docs.locust.io/en/stable
      • 编辑:我查看了文档,他们没有提到此功能尚不可用。看起来文档需要更新?
      • 不,文档已经是最新的了。 “稳定”文档适用于当前版本(0.8.1),而“最新”文档是从 master(存在此功能的地方)生成的。发布后,您将在“稳定”文档中看到它。
      • 啊!好的,现在我明白了。我在网站上找到了“稳定”文档,你是对的,它没有将设置/拆卸列为一项功能。凉爽的。感谢您为我指明了正确的方向,Corey!
      • 计划什么时候发布0.9版本?使用这个功能会很有趣
      猜你喜欢
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多