Тест саранчи с пост-API с заголовками
Когда я пытаюсь запустить тест производительности HTTP.get, этот код отлично работает для меня:
from locust import HttpLocust, TaskSet, task
class ReferenceWsTest(TaskSet):
@task(1)
def index(self):
response = self.client.request(method="GET",
url="/v1/reference/charges/config?chargeTypes=SUBTOWIN",
headers = {
"country": 'DEU'
})
print ("Preview; Response status code:",
response.status_code)
class WebsiteUser(HttpLocust):
task_set = ReferenceWsTest
min_wait = 5000
max_wait = 9000
Хотя, когда я пытаюсь опубликовать API с заголовками, этот код не работает:
from locust import HttpLocust, TaskSet, task
import uuid
datas = """
{"eventCode":"INITPAYOUT","skipCreditValidation":false,"lotId":50017353,"party":{"id":"163","type":"VDR","attributes":{"zip":"88898","country":"ESP","facilityId":"5101","city":"Madrid","mailingCity":"Madrid","operatingCntryCd":"ESP","vatId":"ESB86979853","mailingZip":"88898","paymentFreqValue":"1","bulkPaymentFlag":"false","phone":"34788787888","addrLine2":null,"addrLine1":"Luna","mailingCountry":"ESP","paymentFreq":"MNT","defBankAccountNum":"4UYDyn5Pt8v88joT4plyJQ==","mailingAddrLine1":"Luna","name":"G2.5 Before Pick up Spain Vendor","invRcptFlg":"false","mailingAddrLine2":null,"mailingState":null,"state":null,"paymentTerm":"0D","email":"mamatha.bompelli@gmail.com"},"enrichmentNotRequired":false},"facilityId":5101,"payment":{"bills":[{"billNumber":"59001713","billId":62648,"eventCategoryCode":"PURCHASE","dueAmount":"363.00","sequence":1,"currency":"EUR","hasChargeProduct":false,"exportType":"DMSTC"}],"paymentAmount":"363.00","paymentDate":"2018-09-01T15:19:44.980Z","paymentDetails":[{"sequence":1,"paymentMethod":"BNKTR","paymentMethodId":"1234567890","txnReferenceNum":null,"attributes":{"bankAccountName":"G2.5 Before Pick up Spain Vendor","bankRoutingNumber":"/VwoXekvy23LSGEN7/OUqQ==","bankIBAN":"+Aa8/A7NVvZnO5CSwcGwkUCp+3k/yb0ATcF8rZkoFUA=","bankName":"Yard Portal QA4 BAnk","bankCountry":"ESP"},"amount":"363.00"}]},"correction":false,"referenceBills":[],"copartOwnedLot":false,"accumulation":false,"forcePay":false,"processCurrentFlowCharges":false,"bulkProcess":false,"nothingToProcess":false,"requestLogId":169853}
"""
header = {"country": "ESP","source": "yard","correlationid": "lalalalal","flowId": 1,"Content-type": "application/json"}
class ReferenceWsTest(TaskSet):
@task(1)
def index(self):
header["correlationid"] = my_random_string(10)
response = self.client.post("/v1/events/", datas, headers = header)
print(header)
print(datas)
print ("Preview; Response status code:", response.status_code)
class WebsiteUser(HttpLocust):
task_set = ReferenceWsTest
min_wait = 5000
max_wait = 9000
def my_random_string(string_length=10):
"""Returns a random string of length string_length."""
random = str(uuid.uuid4()) # Convert UUID format to a Python string.
random = random.upper() # Make all characters uppercase.
random = random.replace("-","") # Remove the UUID '-'.
return random[0:string_length] # Return the random string.
И когда запустить тест производительности, я получил ответ, как показано ниже:
[2018-08-20 15:15:40,449] localhost/INFO/stdout: ('Preview; Response status code:', 0)
1 ответ
Решение
Ты создал header
как глобальный, поэтому каждая задача разделяет одно и то же correlationid
, Вы должны сделать свои заголовки внутри своей задачи, чтобы они были уникальными для каждого экземпляра.