Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaskSet min_wait and max_wait are ignored #891

Closed
dblakemore opened this issue Sep 21, 2018 · 7 comments
Closed

TaskSet min_wait and max_wait are ignored #891

dblakemore opened this issue Sep 21, 2018 · 7 comments
Labels

Comments

@dblakemore
Copy link

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.
@aldenpeterson-wf
Copy link
Contributor

aldenpeterson-wf commented Oct 10, 2018

Ah, good catch, looks like

self.wait_function = self.locust.wait_function
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!

@devmonkey22
Copy link
Contributor

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?

@cmcinroy
Copy link

cmcinroy commented Nov 27, 2018

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?

@stevecj
Copy link

stevecj commented Sep 4, 2019

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?

@heyman
Copy link
Member

heyman commented Oct 22, 2019

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())

@cyberw
Copy link
Collaborator

cyberw commented Nov 18, 2019

this is fixed now, right @heyman ?

@heyman
Copy link
Member

heyman commented Nov 18, 2019

Yes it it!

@heyman heyman closed this as completed Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants