Skip to content

Commit

Permalink
Add loadtest file
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMorfield committed Oct 5, 2023
1 parent 29c0b32 commit c51b47d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/update-many-pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import json
import time
from random import *
import threading

# url = "https://pixelcorp.nl/api/single"
url = "http://localhost:5173/api/single"
headers = {'Content-Type': 'application/json'}

def put():
data = {
"x": round(random() * 199),
"y": round(random() * 199),
"color": [255, 0, 0],
"key": "joppe"
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=3)
if response.status_code == 200:
print("Send", data['x'], data['y'], data['color'], "successfully")
else:
print("Failed to send", response.status_code, response.text)
except:
print("Failed to send")

def put_infinite():
while True:
put()

threads = list()
for index in range(1):
x = threading.Thread(target=put_infinite)
threads.append(x)
x.start()
print("Started", len(threads), "threads")

for index, thread in enumerate(threads):
thread.join()

0 comments on commit c51b47d

Please sign in to comment.