0

I am trying to do a local load testing with Locust. I got the test environment up and running and a local build is also working. I am trying to test the responses of a local path and the response I get in the terminal is correct. But the Locust UI and also the statistics after terminating the test give me 100% fail results.

For creating the locust code (I am pretty new to it) I use the postman content and adjusted it. This is the Code for Locust:

from locust import HttpLocust, TaskSet, task, between 
import requests

url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n    {\n        \"appName\": \"test-app\",\n        \"appVersion\": \"1.6.0\"\n    }\n]"

class MyTaskSet(TaskSet):

    @task(2)
    def index(self):
        self.client.get("")
        headers = {
        'Content-Type': 'application/json',
        'Accept':'application/json'
        }
        response = requests.request("POST", url, headers=headers, data = payload)

        print(response.text.encode('utf8'))

class MyLocust(HttpLocust):
    task_set = MyTaskSet
    wait_time = between(2.0, 4.0)

For the Locust swarm I used just basic numbers: Number of total users to simulate: 1 Hatch Rate: 3 Host: http://localhost:8080/registry/downloadCounter

I do not get any results there, the table stays blank. I guess it has something to do with the json format but I am not able to find the solution myself.

I also put a Screenshot of the Terminal response after termination in this post.

Thank you in advance for your help!

Best regards

enter image description here

Kalex
  • 21
  • 1
  • Hi, sorry for pushing. It would be great if someone could help me out with this problem. – Kalex May 07 '20 at 16:17

1 Answers1

0

This helped:

from locust import HttpLocust, TaskSet, task, between 
import requests

url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n    {\n        \"appName\": \"test-app\",\n        \"appVersion\": \"1.6.0\"\n    }\n]"
headers = {'Content-type':'application/json', 'Accept':'application/json'}

class MyTaskSet(TaskSet):

    @task(2)
    def index(self):
        response = self.client.post(url = url, data = payload, headers=headers)

        print(response.text.encode('utf8'))
        print(response.status_code)


class MyLocust(HttpLocust):
    task_set = MyTaskSet
    wait_time = between(2.0, 4.0)
```
Kalex
  • 21
  • 1