{"action":"created","issue":{"url":"https://api.github.com/repos/locustio/locust/issues/236","labels_url":"https://api.github.com/repos/locustio/locust/issues/236/labels{/name}","comments_url":"https://api.github.com/repos/locustio/locust/issues/236/comments","events_url":"https://api.github.com/repos/locustio/locust/issues/236/events","html_url":"https://github.com/locustio/locust/issues/236","id":55561141,"number":236,"title":"confused by multiple requests in on_start","user":{"login":"mblakele","id":101790,"avatar_url":"https://avatars.githubusercontent.com/u/101790?v=3","gravatar_id":"","url":"https://api.github.com/users/mblakele","html_url":"https://github.com/mblakele","followers_url":"https://api.github.com/users/mblakele/followers","following_url":"https://api.github.com/users/mblakele/following{/other_user}","gists_url":"https://api.github.com/users/mblakele/gists{/gist_id}","starred_url":"https://api.github.com/users/mblakele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mblakele/subscriptions","organizations_url":"https://api.github.com/users/mblakele/orgs","repos_url":"https://api.github.com/users/mblakele/repos","events_url":"https://api.github.com/users/mblakele/events{/privacy}","received_events_url":"https://api.github.com/users/mblakele/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-27T01:00:09Z","updated_at":"2015-03-27T15:00:45Z","closed_at":null,"body":"This is with 0.7.2 from pip, and also using the latest from github. It seems that `on_start` isn't expecting more than one request, and does strange things when this happens.\r\n\r\nUse case: django apps often use a guard token that is the same in headers and form, and posting the form has to replay it correctly: `csrfmiddlewaretoken`. If a login form uses this token, then the setup phase must GET the form, parse out the token, and then POST the login request with the right token.\r\n\r\n```\r\nclass UserBehavior(TaskSet):\r\n    def on_start(self):\r\n        \"\"\"\r\n        on_start is called when a Locust start before,\r\n        any task is scheduled\r\n        \"\"\"\r\n        self.login()\r\n\r\n    def login(self):\r\n        # Response from GET will include csrfmiddlewaretoken\r\n        resp = self.client.get(\"/login\")\r\n        token = resp.cookies.get('csrftoken')\r\n        self.client.post(\"/login\",\r\n                       {\"csrfmiddlewaretoken\":token,\r\n                        \"username\":\"joe.test\",\r\n                        \"password\":\"test\"})\r\n\r\n    @task(1)\r\n    def index(self):\r\n        self.client.get(\"/\")\r\n\r\nclass WebsiteUser(HttpLocust):\r\n    task_set = UserBehavior\r\n    min_wait =  500\r\n    max_wait = 1500\r\n\r\n```\r\nIf this locustfile is run with `n=1`, both login requests are visible in the server log. But locust only reports the GET, not the POST. I think this happens because it is counting requests, and expects the `on_start` to only contain one request.\r\n\r\nIf run with `n=2`, the final summary shows both `on_start` requests but the server log also shows `GET /`. With sufficiently large `n` I suppose this doesn't matter, but it would be more accurate to report on all the requests that were made, whatever value `n` has.\r\n\r\nIf the `GET /` task is removed and `n=2`, locust goes into a loop of `IndexError` exceptions.\r\n\r\n```\r\n[2015-01-26 16:34:13,705] localhost/ERROR/stderr: Traceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/locust/core.py\", line 264, in run\r\n    self.schedule_task(self.get_next_task())\r\n  File \"/usr/local/lib/python2.7/site-packages/locust/core.py\", line 325, in get_next_task\r\n    return random.choice(self.tasks)\r\n  File \"/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py\", line 275, in choice\r\n    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty\r\nIndexError: list index out of range\r\n[2015-01-26 16:34:15,032] localhost/ERROR/stderr: Traceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/locust/core.py\", line 264, in run\r\n    self.schedule_task(self.get_next_task())\r\n  File \"/usr/local/lib/python2.7/site-packages/locust/core.py\", line 325, in get_next_task\r\n    return random.choice(self.tasks)\r\n  File \"/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py\", line 275, in choice\r\n    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty\r\nIndexError: list index out of range\r\n```"},"comment":{"url":"https://api.github.com/repos/locustio/locust/issues/comments/86965178","html_url":"https://github.com/locustio/locust/issues/236#issuecomment-86965178","issue_url":"https://api.github.com/repos/locustio/locust/issues/236","id":86965178,"user":{"login":"tom-dalton-fanduel","id":7839062,"avatar_url":"https://avatars.githubusercontent.com/u/7839062?v=3","gravatar_id":"","url":"https://api.github.com/users/tom-dalton-fanduel","html_url":"https://github.com/tom-dalton-fanduel","followers_url":"https://api.github.com/users/tom-dalton-fanduel/followers","following_url":"https://api.github.com/users/tom-dalton-fanduel/following{/other_user}","gists_url":"https://api.github.com/users/tom-dalton-fanduel/gists{/gist_id}","starred_url":"https://api.github.com/users/tom-dalton-fanduel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tom-dalton-fanduel/subscriptions","organizations_url":"https://api.github.com/users/tom-dalton-fanduel/orgs","repos_url":"https://api.github.com/users/tom-dalton-fanduel/repos","events_url":"https://api.github.com/users/tom-dalton-fanduel/events{/privacy}","received_events_url":"https://api.github.com/users/tom-dalton-fanduel/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T15:00:45Z","updated_at":"2015-03-27T15:00:45Z","body":"None of the requests involved in my tests return or make redirects."}}