Commit 4d84cf38 authored by Dmytro Halinovskyi's avatar Dmytro Halinovskyi
Browse files

Add load tests

parent afb9f902
import asyncio
import json
from datetime import datetime
import aiohttp
from timeit import default_timer as timer
procedure = {
"sellingMethod": "timber-english-initial-auction-manual",
"auctionPeriod": {
"startDate": "2020-06-22"
},
"title": {
"uk_UA": "Аукціон з продажу необробленої деревини",
"en_US": "Timber english"
},
"description": {
"uk_UA": "Аукціон з продажу необробленої деревини",
"en_US": "Timber english"
},
"accessDetails": {
"uk_UA": "Порядок та можливий час ознайомлення з лотом",
"en_US": "Auction access details"
},
"sellingEntity": {
"identifier": {
"id": "12345678",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 45a",
"en_US": "Khreschatyk, 45a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01002",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор",
"en_US": "Admin"
},
"telephone": "+380123456789",
"faxNumber": "+380123456789",
"email": "admin@example.com"
}
},
"previousAuctionId": "UA-PS-1122-33-44-000000-0",
"lotId": "UA-PS-19991212-00000",
"x_documentRequirements": {
"uk_UA": "Вимоги до оформлення документів",
"en_US": "Document requirements"
},
"value": {
"currency": "UAH",
"amount": 1000
},
"guarantee": {
"currency": "UAH",
"amount": 0
},
"tenderAttempts": 2,
"bankAccount": [],
"items": [
{
"id": "b75870ac-dad2-405a-9aae-ecea87cd38f7",
"description": {
"uk_UA": "сКруглі лісоматеріали",
"en_US": "sRound timber"
},
"classification": {
"scheme": "CAV",
"id": "03410000-7"
},
"additionalClassifications": [
{
"scheme": "timberProductionYear",
"id": "2020"
},
{
"scheme": "timberProductionQuarter",
"id": "2"
},
{
"scheme": "timberSortment",
"id": "sRound"
},
{
"scheme": "timberLength",
"id": "2,2 - 3,5"
},
{
"scheme": "timberStorage",
"id": "01"
},
{
"scheme": "timberDiameter",
"id": "D1a"
},
{
"scheme": "timberSpecies",
"id": "BEDA"
},
{
"scheme": "CPVS",
"id": "QB49-3"
},
{
"scheme": "timberClass",
"id": "b"
}
],
"unit": {
"code": "H87"
},
"unitValue": {
"currency": "UAH",
"amount": 10
},
"quantity": 900,
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
}
}
],
"bids": [
{
"id": "6c2c85665a8f44b18b9f48ddbd629b5b",
"ownerToken": "4156562f-2ce1-4fa5-b25f-48e2730e1b15",
"owner": "test1",
"bidders": [
{
"identifier": {
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор1",
"en_US": "Admin1"
},
"telephone": "+380996872350",
"faxNumber": "+380996872350",
"email": "admin@example.com"
}
}
],
"status": "active",
"value": {
"currency": "UAH",
"amount": 1
}
},
{
"id": "6a2c85665a8f44b18b9f48ddbd629a4a",
"ownerToken": "4156662f-2ce1-4fa5-b25f-48e2730e1b15",
"owner": "test1",
"bidders": [
{
"identifier": {
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор2",
"en_US": "Admin2"
},
"telephone": "+380996872350",
"faxNumber": "+380996872350",
"email": "admin@example.com"
}
}
],
"status": "active",
"value": {
"currency": "UAH",
"amount": 1
}
}
],
"minimalStep": {
"currency": "UAH",
"amount": 10
},
"discount": {
"discount": False
}
}
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/51.0.2704.103 Safari/537.36'}
# SANDBOX
url = "wss://auction-sandbox.prozorro.sale/api/auctions/rooms/{}/feed"
create_room_url = "https://auction-sandbox.prozorro.sale/api/auctions/rooms"
procedure_url = "https://procedure-sandbox.prozorro.sale/api/procedures"
auth = {'Authorization': 'f62367a8-c6e6-414f-8a73-b0939192b926'}
# DEV
# url = "wss://ps-auction-dev.kube.raccoongang.com/api/auctions/rooms/{}/feed"
# procedure_url = "https://ps-procedure-dev.kube.raccoongang.com/api/procedures"
# create_room_url = "https://ps-auction-dev.kube.raccoongang.com/api/auctions/rooms"
# auth = {'Authorization': 'auction_token'}
async def create_auction():
room = {}
data = json.dumps(procedure)
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False)) as sess:
for i in range(2):
async with sess.post(procedure_url, data=data, headers=auth) as resp:
print(resp.status)
res = await resp.json()
async with sess.get(f'{procedure_url}/{res["id"]}', headers=auth) as resp:
print(resp.status)
res = await resp.json()
room[res["auctionId"]] = {
"bidder_id": "6c2c85665a8f44b18b9f48ddbd629b5b",
"acc_token": "4156562f-2ce1-4fa5-b25f-48e2730e1b15"
}
data = json.dumps(room)
async with sess.post(create_room_url, data=data, headers=auth) as resp:
print(resp.status)
res = await resp.json()
print('Room:', res)
return res['room_id']
async def main():
room_id = await create_auction()
room_url = url.format(room_id)
i = 0
try:
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False)) as sess:
async with sess.ws_connect(room_url, headers=header) as ws:
start = timer()
print(f'Connected: {datetime.now()}')
async for _ in ws:
i += 1
print(f'Received msg {i}: {datetime.now()}')
if i >= 100:
end = timer()
print(f'Disconnected: {datetime.now()}')
print(f'Received {i} messages in {end - start} sec')
await ws.close()
break
finally:
print(f'Disconnected: {datetime.now()}')
# async def main():
# # room_id = await create_auction()
# room_url = 'ws://0.0.0.0:7777/api/auctions/rooms/4489fbc1b242491dba91043e0d855f7c/feed?bidder_id=a1f44e85-96ec-4898-9c42-86cb42f5beb1&acc_token=51c13c45-fb24-46c2-a3ac-adf64c05d791'
# i = 0
# try:
# async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False)) as sess:
# async with sess.ws_connect(room_url, headers=header, heartbeat=2) as ws:
# start = timer()
# print(f'Connected: {datetime.now()}')
# async for x in ws:
# print(x)
# i += 1
# print(f'Received msg {i}: {datetime.now()}')
# if i >= 100:
# end = timer()
# print(f'Disconnected: {datetime.now()}')
# print(f'Received {i} messages in {end - start} sec')
# await ws.close()
# break
# finally:
# pass
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
import asyncio
import json
import aiohttp
procedure = {
"sellingMethod": "timber-english-initial-auction-manual",
"auctionPeriod": {
"startDate": "2020-06-22"
},
"title": {
"uk_UA": "Аукціон з продажу необробленої деревини",
"en_US": "Timber english"
},
"description": {
"uk_UA": "Аукціон з продажу необробленої деревини",
"en_US": "Timber english"
},
"accessDetails": {
"uk_UA": "Порядок та можливий час ознайомлення з лотом",
"en_US": "Auction access details"
},
"sellingEntity": {
"identifier": {
"id": "12345678",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 45a",
"en_US": "Khreschatyk, 45a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01002",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор",
"en_US": "Admin"
},
"telephone": "+380123456789",
"faxNumber": "+380123456789",
"email": "admin@example.com"
}
},
"previousAuctionId": "UA-PS-1122-33-44-000000-0",
"lotId": "UA-PS-19991212-00000",
"x_documentRequirements": {
"uk_UA": "Вимоги до оформлення документів",
"en_US": "Document requirements"
},
"value": {
"currency": "UAH",
"amount": 1000
},
"guarantee": {
"currency": "UAH",
"amount": 0
},
"tenderAttempts": 2,
"bankAccount": [],
"items": [
{
"id": "b75870ac-dad2-405a-9aae-ecea87cd38f7",
"description": {
"uk_UA": "сКруглі лісоматеріали",
"en_US": "sRound timber"
},
"classification": {
"scheme": "CAV",
"id": "03410000-7"
},
"additionalClassifications": [
{
"scheme": "timberProductionYear",
"id": "2020"
},
{
"scheme": "timberProductionQuarter",
"id": "2"
},
{
"scheme": "timberSortment",
"id": "sRound"
},
{
"scheme": "timberLength",
"id": "2,2 - 3,5"
},
{
"scheme": "timberStorage",
"id": "01"
},
{
"scheme": "timberDiameter",
"id": "D1a"
},
{
"scheme": "timberSpecies",
"id": "BEDA"
},
{
"scheme": "CPVS",
"id": "QB49-3"
},
{
"scheme": "timberClass",
"id": "b"
}
],
"unit": {
"code": "H87"
},
"unitValue": {
"currency": "UAH",
"amount": 10
},
"quantity": 900,
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
}
}
],
"bids": [
{
"id": "6c2c85665a8f44b18b9f48ddbd629b5b",
"ownerToken": "4156562f-2ce1-4fa5-b25f-48e2730e1b15",
"owner": "test1",
"bidders": [
{
"identifier": {
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"additionalIdentifiers": [
{
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
}
],
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор1",
"en_US": "Admin1"
},
"telephone": "+380996872350",
"faxNumber": "+380996872350",
"email": "admin@example.com"
}
}
],
"status": "active",
"value": {
"currency": "UAH",
"amount": 1
}
},
{
"id": "6a2c85665a8f44b18b9f48ddbd629a4a",
"ownerToken": "4156662f-2ce1-4fa5-b25f-48e2730e1b15",
"owner": "test1",
"bidders": [
{
"identifier": {
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
},
"additionalIdentifiers": [
{
"id": "12312312",
"scheme": "UA-EDR",
"legalName": {
"uk_UA": "ЕДРПОУ",
"en_US": "EDRPOU"
}
}
],
"address": {
"streetAddress": {
"uk_UA": "Хрещатик, 43a",
"en_US": "Khreschatyk, 43a"
},
"locality": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"region": {
"uk_UA": "Київ",
"en_US": "Kyiv"
},
"postalCode": "01001",
"countryName": {
"uk_UA": "Україна",
"en_US": "Ukraine"
}
},
"contactPoint": {
"name": {
"uk_UA": "Адміністратор2",
"en_US": "Admin2"
},
"telephone": "+380996872350",
"faxNumber": "+380996872350",
"email": "admin@example.com"
}
}
],
"status": "active",
"value": {
"currency": "UAH",
"amount": 1
}
}
],
"minimalStep": {
"currency": "UAH",
"amount": 10
},
"discount": {
"discount": False
}