-1

I'm using Locust to run a load test, to my surprise all of the POST APIs I tried calling from it returns "Internal Server Error - 500", but if I run the same APIs from JMeter they run well. I checked and saw like LocustIO prepends and apostrophe at the end of each call. This is a screen shot Locust Failure UI

This is my setup code:

from locust import HttpLocust, TaskSet, task

class justTestApi(TaskSet):

    @task(1)
    def accountInquiry(self):
        self.client.post("/users", {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  });

class WebsiteUser(HttpLocust):
    task_set = justTestApi
    min_wait = 5000
    max_wait = 9000
    host = "https://jsonplaceholder.typicode.com"
    stop_timeout = 200
false
  • 10,264
  • 13
  • 101
  • 209
ken4ward
  • 2,246
  • 5
  • 49
  • 89
  • 1
    What does your server log show? A 500 is coming back from the server, not from Locust. – enderland Mar 28 '18 at 15:11
  • Locust is passing apostrophe and comma to the end of the endpoint that's the problem, and I don't know why. An example is this: ```https://myapp.com/users',``` This is what it is sending as the endpoint. – ken4ward Mar 28 '18 at 19:32
  • 1
    That `'` is the closing apostrophe to the beginning of the error string... which clearly articulates the error in question... – enderland Mar 28 '18 at 20:23

1 Answers1

-1

Finally got it working using this tutorial - https://andrew-jones.com/blog/load-testing-with-locust/. This is how the setup should look like when trying to test a post restful call. I read an argument that LocustIO can't be used to test https, this test faulted that claim. It can be used to test https as well.

from locust import HttpLocust, TaskSet, task

json = """
[{
  userId: 1,
  id: 1,
  title: "quidem molestiae enim"
}]
"""

class MyTaskSet(TaskSet):
    @task(1)
    def send(l):
        l.client.post("/albums", json) 

class MyLocust(HttpLocust):
    task_set = MyTaskSet
    min_wait = 5000
    max_wait = 15000
    # host = "http://www.somaku.com"
    host = "https://jsonplaceholder.typicode.com"
    stop_timeout = 200
ken4ward
  • 2,246
  • 5
  • 49
  • 89