Locust: TaskSet min_wait and max_wait are ignored

Created on 21 Sep 2018  ·  7Comments  ·  Source: locustio/locust

Description of issue / feature request

min_wait / max_wait overrides in TaskSet class not working correctly. When setting min_wait and max_wait values in a TaskSet class, the values seem to be ignored and the default values of 1000 (from the Locust class) are used instead.

I've done some digging into this and I _think_ I know where the problem lies. The TaskSet's wait_function is automatically set to the locust's wait_function if undefined, but the locust's wait_function was defined as a lambda using its own min_wait and max_wait values. As such, the TaskSet's min_wait and max_wait value have no effect.

You can get around this by assigning a new lambdawait_function to the TaskSet, but this defeats the purpose of being able to override the min_wait and max_wait values.

Expected behavior

When setting a min_wait and max_wait value of 10000 in a TaskSet class, tasks for each Locust should be spawned 10 seconds apart

Actual behavior

When setting a min_wait and max_wait value of 10000 in a TaskSet class, tasks for each Locust are still spawned 1 second apart (which is the default value)

Environment settings (for bug reports)

  • OS: Alpine Linux (docker image)
  • Python version: 2.7
  • Locust version: 0.9.0

Steps to reproduce (for bug reports)

  • Create a TaskSet class which inherits from the base TaskSet, with a min_value and max_value of 10000
  • Create a single task on the TaskSet class
  • Create a Locust class which inherits from the base HttpLocust, with its task_set property set to the TaskSet class created in step one
  • Start swarming with 1 user. You would expect the task to spawn every 10 seconds, but it spawns every 1 second.
bug

All 7 comments

Ah, good catch, looks like https://github.com/locustio/locust/blob/30275af9f2acd7f01a5ea04382610b4f3c2f7daa/locust/core.py#L320 should also be:

lambda self: random.randint(self.min_wait,self.max_wait)

in both the TaskSet as well as Locust.

@cgoldberg @heyman @mbeacom anyone have thoughts on this? Fixing it _will_ change behavior for anyone who has defined TaskSet min/max. I'm unsure if this is enough of an issue to warrant not fixing this though.

Nice bug writeup too!

I just found the same problem. I ended up just creating a TaskSet mixin that set it on all my tasksets, but it would be nice to be able to inherit from the locust's wait_function and have it still use the taskset's min_wait and max_wait.

I think python has the ability to rebind self like that, but I thought the lambda approach would have done that. Maybe because we're in python 2.7, and I think was solved/handled in py 3 differently?

I just hit this problem, as well.
Nice that it was reported so thoroughly (I read the issue knowing I would likely hit the problem).

I'm not clear on the workaround... can anyone provide more direction?

I also seem to be experiencing the problem. If that MR fixes the issue, then can we have it merged and included in a release?

Oh, this should definitely be fixed.

Nice debugging. I didn't realise that lambda functions also became bound methods when declared within a class definition.

Here's a simple (currently failing) test for this:

    def test_different_wait_times_on_locust_and_taskset(self):
        class MyTaskSet(TaskSet):
            min_wait = 1
            max_wait = 1
        class MyLocust(Locust):
            min_wait = 200
            max_wait = 200
        taskset = MyTaskSet(MyLocust())
        self.assertEqual(0.001, taskset.get_wait_secs())

this is fixed now, right @heyman ?

Yes it it!

Was this page helpful?
0 / 5 - 0 ratings