0

I have a locustfile.py that repeatedly makes the same http post request.

The first post contains all of the request headers that I'm expecting and the post returns with http 200.

The next post is missing all headers with the exception of Content-Length: 0. This of course fails.

It continues with every other request having the proper content-length, content-type, authorization, etc.

Any suggestions on why these requests don't always have the headers? On a separate note, I've also noticed similar behavior in Postman.

UPDATE: Below is my locustfile.py. This appears to be related to keep-alive on the nginx server. How can I disable keep-alive in my locustfile to further test?

from locust import TaskSet, task
from locust import HttpLocust
import os
from datetime import datetime


class UserBehavior(TaskSet):
    
    def __init__(self, *args, **kwargs):
        super(UserBehavior, self).__init__(*args, **kwargs)

    def on_start(self):
        # Use PID as unique name for locust instance
        self.__name = 'locust_'+str(os.getpid())
        self.__id = 1


    @task(1)
    def create_post(self):     
        date_time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
        data = "<xmldata timestamp= " + date_time + "> </xmldata>"

        user = 'username' 
        passwd = 'userpasswd' 
        header = {'Content-Type': 'application/xml', 'User-Agent': 'locust' }

        response = self.client.post('/path/'+str(self.__id)+'/info', data=data, headers=header, auth=(user,passwd), timeout=6000, name=self.__name)

        print("Response headers: " + str(response.headers))
        print("Request headers: " + str(response.request.headers))
        if response.status_code != 200:
           print("Response status code: " + str(response.status_code))
        if response.status_code > 200:
            print("Response content: " + response.text)
            print("Response reason " + response.reason)


class WebsiteUser(HttpLocust):
    task_set = UserBehavior      
    min_wait = 5000 
    max_wait = 10000  
Barry
  • 417
  • 6
  • 18
  • Could you also share your locustfile.py? – pavelsaman Aug 20 '20 at 18:44
  • @pavelsaman I posted my locustfile.py in my update to the original post above. It appears to be related to the keep-alive from the proxy server. I'm trying to figure out how to get the client to not send the header 'Connection': 'keep-alive' – Barry Aug 21 '20 at 03:21

0 Answers0