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

How do i control diving into nested tasksets? #1097

Closed
TraGicCode opened this issue Sep 27, 2019 · 2 comments
Closed

How do i control diving into nested tasksets? #1097

TraGicCode opened this issue Sep 27, 2019 · 2 comments

Comments

@TraGicCode
Copy link

I have the below locustfile

class CartPage(TaskSet):
    @task(1)
    def apply_promo_to_cart(self):
        # stuff here
      
    @task(1)
    def remove_item_from_cart(self):
      # stuff here


class ProductPage(TaskSet):
    tasks = {CartPage:1}
    @task(1)
    def change_product_color(self):
        # stuff here
      
    @task(1)
    def add_product_to_cart(self):
      # stuff here


class WebsiteUser(HttpLocust):
    task_set = ProductPage
    min_wait = 1000
    max_wait = 5000

When the locust enters the ProductPage TaskSet how do i ensure that anytime the "add_product_to_cart" method is called locust then starts using the CartPage TaskSet. Essentially In the browser when the user hits the button to add product to cart they go to the cart page and i want the locust to behave the same way. Right now it's sometimes executing change_product_color and then trying to go to the cart but it's empty!

@skivis
Copy link
Contributor

skivis commented Sep 30, 2019

@TraGicCode In your example above you could just add self.schedule_task(CartPage, first=True) to the end of your add_product_to_cart() task and get the behavior you're looking for.

Although if you leave tasks = {CartPage: 1} (weight 1) the locust will still be able to go from change_product_color to CartPage.remove_item_from_cart. One way of solving this would be to have the weight of CartPage be 0, meaning the locust will never automatically schedule CartPage unless it hits add_product_to_cart first.

Alternatively you could just use sequential tasks instead:

class ProductPage(TaskSequence):
    @seq_task(1)
    def change_product_color(self):
        # stuff here

    @seq_task(2)
    def add_product_to_cart(self):
        # stuff here

    @seq_task(3)
    class CartPage(TaskSet):
        @task(1)
        def apply_promo_to_cart(self):
            # stuff here

        @task(1)
        def remove_item_from_cart(self):
            # stuff here
            self.interrupt(reschedule=False)


class WebsiteUser(HttpLocust):
    task_set = ProductPage
    min_wait = 1000
    max_wait = 5000

@TraGicCode
Copy link
Author

Thanks for the useful info. I was trying to avoid the sequential tasks allow for more randomness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants