locust: Exceptions raised in setup method causes Locust to break

In locustio 0.13.5, there is a very odd bug that prevents the setup method from using requests to make HTTP requests. When doing an HTTP POST request, the setup function unexpectedly returns. No exception is printed, but the remainder of the function does not execute. This is what my code looks like (edited down for confidentiality):

class MyLocust(HttpLocust):
    def setup(self):
        print('Creating test data')
    
        response = requests.post('https://my-service.company.com', json=test_data)
        assert response.status_code == 201
    
        print('Created test data')  

I added a try/catch to my code and apparently the requests.post() call throws a GreenletExit exception. After much consternation I was able to narrow the issue down to gevent. It appears that the gevent._ssl3 module’s call to self._wait(self._read_event, timeout_exc=_SSLErrorReadTimeout) on line 332 throws this GreenletExit error.

Important note: this error does not manifest in locustio 0.12.2 or lower.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, preferably you could use the setup() function the same in both the Locust and the TaskSet. But if there are technical limitations that prevent this, having two functions that operate subtly differently is not a very good experience.

@cyberw I tried moving the setup() into the TaskSet and it appears to work! I still think you should do something about setup() in the Locust throwing this error though. The fact that it appears to support normal setup() functions is misleading and, if the TaskSet is the preferred place to set it, perhaps it would be better to deprecate that particular function.