0

We want to simulate users reading forums. Thus we want -

class ReadPostsInOneForum(TaskSet):
    @task
    def read(self):
        forum_id = (want to get it from parent) # TODO HERE!!!
        post_id = _get_random_int()
        self.client.get('/forums/'+forum_id+'/'+post_id)

class ReadForums(TaskSet):
    @task
    def read(self):
        forum_id = _get_some_values()
        start_task_set(ReadPostsInOneForum, forum_id=forum_id) # TODO HERE!!!

Questions:

  1. How to pass parameters to a child taskset?
  2. How to start another taskset within a @task method?

p.s. There seems one way, by using self.parent.whatever_variable, but I would prefer a more Pythonic & OOP solution, such as passing some parameters in constructor.

pppery
  • 3,731
  • 22
  • 33
  • 46
ch271828n
  • 15,854
  • 5
  • 53
  • 88

1 Answers1

0

There is nothing preventing a single task from making multiple requests. Just put everything in a single task (optionally putting the self.client.get('/forums/'+forum_id+'/'+post_id) in a loop, if you want to do it multiple times)

Or put it in a separate method in the same class (that you then call from the main/ReadForums method), and just dont tag it with @task (and use either instance variables or method parameters to pass things like forum_id)

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40